Download

{{#getPages}} helper

{{getPages}} is a helper 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 post 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 defines an HTML prefix, while the third parameter adds an HTML suffix to the output.

Moreover, you can enhance the dynamic fetching and display of pages by leveraging the pages dropdown control from the Theme Settings API. Combined with the concatenate helper, this allows for the seamless merging of query string options with theme option values. This functionality enables users to select specific pages to display within your theme. To implement this, reference the selected pages directly through the theme configuration. For example, if you have a pages dropdown control named pagesDropdown in your Theme Settings, its value can be dynamically utilized with the getPages helper, as demonstrated below:

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

In this setup, @config.custom.featuredPagesDropdown directly references the comma-separated page IDs the user selects through the dropdown control. This method allows the displayed pages to be dynamically managed via theme settings, providing theme users with high customization and flexibility.

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

What are you waiting for?

Start building your site today.

  1. 1 Download Publii
  2. 2 Write your content
  3. 3 Publish your site
Create website