Front Matter Templates
This guide assumes you already have an understanding of Front Matter and how it works with Forestry. If this isn’t the case, you can read up on it in the Front Matter doc.
What are Front Matter Templates?
FMTs can be creating using the CMS, or by creating Config Files.
FMTs can only be accessed in the CMS by team members with the Developer or Site Owner role.
Creating an FMT
FMTs can be created from scratch, or can be created using the fields from an existing page that doesn’t have an FMT applied to it.
Creating an FMT from Existing Pages
To create an FMT from an an existing page, navigate to the page you wish to use as the basis for your FMT.
Next, click the “…” button in the toolbar, then click Create Template.
In the modal that opens, click Create Template. This will create the new template and redirect you to the Front Matter Template editor.
When creating an FMT from an existing page, the FMT will be named after the page. Make sure you rename it if that’s not the name you desire!
Creating an FMT from Scratch
To create a Front Matter Template from scratch, navigate to the Front Matter page, and click Add Template.
You will now be redirected to the FMT editor. Enter a name for your new FMT, and then click Save Changes.
To edit an FMT, navigate to the Front Matter page in the CMS, and click the FMT you wish to edit from the list.
On the left, you’ll see a preview of how your FMT will look in the editors, and on the right you’ll see the list of available field types.
Turn on the Is Partial toggle to designate this FMT as a Partial Front Matter Template. Partial FMTs are used with the Blocks field type.
When creating a Partial Front Matter Template, you have the option of setting the Display Field. This field is used when displaying the list of blocks created with a Blocks field type.
When you create a new Partial FMT, this dropdown will initially be empty. As you add field definitions to your FMT, these fields will appear as Display Field options.
When Blocks are created in your content, the value of each template’s Display Field will appear with the block label.
Adding a Field
To add a field, click the Add button under the field type you’d like to add. This will add the field to the bottom of your FMT.
The field editor will open for the new field, and prompt you to configure the field. All fields share some common options:
- Label: the human-friendly label shown above the input field in the editor.
- Name: the key stored in your content’s front matter. It is used to access this field in your templates.
- Description: (Optional) a human friendly description of what the field does and/or instructions for your editors.
See the field documentation for a list of all options available for each field.
Editing a Field
To edit a field already added to your FMT, click the cog icon to the right of the field in the left pane.
Fields can be reordered by clicking the up and down arrows to the left of a field.
Removing a Field
To remove a field from your FMT, click the trash icon to the right of the field in the left pane.
Accidentally removed a field from your FMT? Fear not! All changes to FMTs are committed to your Git repository, and can easily be reversed by a developer!
Default values for FMTs can be added. These defaults are applied when creating a new page in Forestry.
Field defaults are only applied when creating new pages and aren’t intended to be used as a fallback value for when no value is provided. For this, see How do I set fallback/hidden values for Front Matter?
Any field in an FMT can be hidden. This hides the field in the editors, but allows developers to set default values or maintain the field for legacy purposes.
This can be used to set default values when creating new pages for fields that shouldn’t be modified by an editor. Check out our post on 3 tips for mastering blocks for some examples.
Applying FMTs to Content
FMTs follow a “no-modification” rule. When applying an FMT to content, Forestry will not modify any existing values, and it will not remove values that are not part of the FMT.
Applying to Pages
To apply an FMT to an individual page, navigate to the page you want to apply the FMT to and click the Settings button, and then select Change Template.
In the modal that opens, select the FMT you wish to apply to the page from the dropdown, and then click close.
Applying to Content Types
FMTs can be applied to all pages in a content type using the
settings.yml config file. See the Config Files documentation for more information.
Applying an FMT to a content type will apply the FMT to any page without an FMT already applied to it. It will also make that FMT the default option when creating new pages.
Caught a mistake or want to contribute to the docs? Edit this page on Github!