Page templates and Templated pages

How to create reusable Page templates (Parent) which can be used to create many Templated pages (Child) with the same layout and style.

Definitions

Page template (Parent)

This page powers the content, widgets and styles that will be used by all Templated pages (Child). All modules added to the page will be displayed on the Template page (Child) created using this Page template.

These pages are never published on the actual site, and are only used for templating purposes.

Template page (Child)

These are all the individual pages created using the Page template (Parent). These pages do not contain modules or content, and usually only contain the custom fields set on the page as well as the Page path, SEO title tag, etc.

Adding a Page template (Parent)

  • Go to "Page > Add new page"

  • Select "Page template (Parent)" as the Type. You can select a Page name that you will recognize in the future.

  • After the page is created, you will need to go to "Page > Page options" and set a "Template name". Example: some_unique_template_name.

    • Note: This is the alias for the Page template that will be used when adding Templated pages (Child).

Normally all the content within the Page template is static, but for any dynamic content that is typically controlled using custom fields set on each Templated page.

Example of accessing the custom fields for the page that has a Headline, Sub-headline and Page content HTML.

<h1>{{ page.custom_fields.headline }}</h1>
<h2>{{ page.custom_fields.sub_headline }}</h2>
{{ page.custom_fields.page_content|safe }}

Adding Template pages (Child)

  • Go to "Page > Add new page"

  • Select "Templated page (Child)" as the Type

  • This will display a "Custom page type" field. This is where you would enter the "Template name" set on the Page template you created. Example: some_unique_template_name

  • After adding the page, you can control:

    • Page title, name, URL path, etc under "Page > Page options"

    • Control the custom fields for the Page under "Page > Custom fields"

For these pages, you will not see the content within the Site builder, but if you view the page on the Preview URL you should see the Page template (Parent) content, with the dynamic values from the custom fields displayed.

Linking to Templated pages

When using Templated sub pages it is typical to have a page within the site (either the home page or a sub page) that lists and links to all the Templated pages of a certain type.

We have a templating utility to allow to you filter and get a list of these pages.

Example of list of templated pages by type

The below example will grab a list of all the custom pages (of type some_unique_template_name) that are also published, and then order them by the Page name

{% set subpages = pages.filter({'custom_page_type': 'some_unique_template_name', 'active': true}, order_by='name') %}
<ul>
    {% for subpage in subpages %}
        <li><a href="{{ subpage.path }}">{{ subpage.name }}</a></li>
    {% endfor %}
</ul>

Last updated