Download

{{#getPagesByCustomFields}} helper

The {{getPagesByCustomFields}} helper is designed to retrieve page data based on the criteria defined by custom fields. This powerful feature allows for more precise control over which pages are displayed.

Syntax

The basic syntax for {{getPagesByCustomFields}} involves specifying a query string that includes several parameters to define the search criteria:

{{#getPagesByCustomFields "PARAMETERS"}}
    <h2>{{ title }}</h2>
    <div>{{{ excerpt }}}</div>
{{/getPagesByCustomFields}}

Example: 

{{#getPagesByCustomFields "count=5&customField=indexTest1&customFieldValue=XYZ&customFieldCompare=not-equals"}}
    <h2>{{ title }}</h2>
    <div>{{{ excerpt }}}</div>
{{/getPagesByCustomFields}}

This example will display up to 5 posts where the custom field indexTest1 does not equal XYZ.

QueryString Options

  • count: Specifies the number of pages to include in the result. Use -1 to return all pages matching the criteria.
  • customField: Indicates the custom field to filter pages by.
  • customFieldValue: Specifies the expected value of the custom field for a page to be included in the results.
  • customFieldCompare: Defines how to compare the custom field's value with customFieldValue. Options include:
    • equals (default): Selects pages where the custom field value matches customFieldValue.
    • not-equals: Selects pages where the custom field value does not match customFieldValue.
    • greater, greater-equals, lesser, lesser-equals: For numeric comparisons.
    • starts-with, ends-with, contains, not-contains: For string comparisons.
  • excluded: Lists IDs of pages to exclude from the results.
  • offset: Sets the number of pages to skip from the beginning of the result set.
  • orderby: Determines the field by which to order the results. Can be a standard field or a customField.
  • ordering: Specifies the direction of sorting (e.g., asc, desc, random).
  • orderbyCompareLanguage: If orderby=customField, allows specifying the locale for sorting, useful for language-specific sorting rules.

Detailed customFieldCompare Options

The customFieldCompare parameter in the {{getPagesByCustomFields}} helper allows for flexible comparisons between the specified customFieldValue and the values within the custom fields of pages. Understanding the available options for this parameter can significantly broaden your content display's customization and filtering capabilities.

Available  Values

  • equals (default value): Selects pages where the custom field's value exactly matches the customFieldValue.
  • not-equals: Selects pages where the custom field's value does not match the customFieldValue.
  • greater: Targets pages where the custom field's value is greater than the customFieldValue. This is primarily used for numerical comparisons.
  • greater-equals: Selects pages where the custom field's value is greater than or equal to the customFieldValue, again mainly for numerical values.
  • lesser: Filters for pages where the custom field's value is less than the customFieldValue, suitable for numeric comparisons.
  • lesser-equals: Chooses pages where the custom field's value is less than or equal to the customFieldValue, used for numbers.
  • starts-with: Finds pages where the custom field's value begins with the sequence specified in customFieldValue.
  • ends-with: Filters pages where the custom field's value ends with the sequence specified in customFieldValue.
  • contains: Selects pages where the custom field's value contains the sequence specified in customFieldValue.
  • not-contains: This is the opposite of contains; it selects pages where the custom field's value does not contain the specified sequence.

Understanding these options allows for precise control over which pages are retrieved based on custom field values, offering a powerful tool for customizing the display of content on your site.

IMPORTANT: It requires 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