{{#getPages}} helper

{{getPages}} is a helper used to retrieve page data regardless of the current context.

Syntax:

{{#getPages "pageID1,pageID2,pageID3" "before" "after"}}
...
{{/getPages}}

Example:

{{#getPages "PAGE_ID_1,PAGE_ID_2,PAGE_ID_N" "<ul>" "</ul>"}}
<li>
    <h2>{{ title }}</h2>
    <div>{{{ excerpt }}}</div>
</li>
{{/getPages}}

Pages are ordered by the ID order in the string.

You can also use the @index variable to detect the page number in the specified collection:

{{#getPages "1,2,3" "<ul>" "</ul>"}}
<li>
    <h2>{{ title }}</h2>
    <div>{{{ excerpt }}}</div>
    {{#checkIf @index '==' 0}}
    <p>IT'S THE FIRST ELEMENT!</p>
    {{/checkIf}}
</li>
{{/getPages}}

The second parameter creates an HTML prefix, and the third parameter creates an HTML suffix for the generated output.

Additionally, it is possible to enhance the dynamic fetching and display of pages by utilizing the pages dropdown control from the Theme Settings API, in conjunction with the concatenate helper to combine query string options with theme option values. This control allows users to select specific pages to be displayed. Integrating this functionality within your theme involves directly referencing the selected pages through the theme configuration. For instance, if you have a pages dropdown control named pagesDropdown in your Theme Settings, its value can be dynamically used with the getPages helper, as shown below:

{{#getPages (concatenate  @config.custom.pagesDropdown) "<ul>" "</ul>"}}
    <li>
        <h2>{{ title }}</h2>
        <div>{{{ excerpt }}}</div>
    </li>
{{/getPages}}

In this setup, @config.custom.featuredPagesDropdown directly refers to the comma-separated page IDs the user selects through the dropdown control. This approach ensures that the displayed pages can be dynamically controlled via theme settings, offering a high level of customization for theme users.

IMPORTANT: It requires availability of the @website.contentStructure global variable

Create your first website with Publii

Join thousands of creators who chose independence. Create content locally and publish lightning-fast, secure websites on your own terms.

Download Publii

Free and open source. Windows, macOS and Linux.

Read the getting started guide