• ♡ Sponsor

    newPagelist

    #Filter #Object #Pagelist #Regex #Sort

    Creates a new pagelist object. The current pagelist will be replaced. A foreach loop can be used to iterate over the pagelist object. This method does not have any output. To only update the configuration of the current pagelist, without resetting all other parameters, the pagelist method can be used instead.

    <@ newPagelist { options } @>
    

    Options

    context: false String|false
    An optionally fixed URL for the context of a pagelist of type breadcrumbs or children. In case this parameter is false, within a loop the context always changes dynamically to the current page.
    excludeCurrent: false Boolean
    Defines whether the current page is excluded from the pagelist.
    excludeHidden: true Boolean
    Defines whether hidden pages are excluded from the list.
    filter: false String|false
    Filters the pagelist by a given tag.
    limit: NULL Integer|NULL
    Limits the pagelist to a maximum number of pages.
    match: false JSON String|false
    Filters the pagelist by a set of variable/regex combinations. While iterating the set of combinations, all pages where a given variable value is not matching its assigned regex are removed from the pagelist. Note that the set of combinations has to be passed as a JSON formatted string and not as a JSON object. A valid value looks like '{"url": "/(work|blog)/"}' or even '{"url": "@{ regex }"}'.
    offset: 0 Integer
    Offsets the selection of pages. The given number of pages will be stripped from the start of the selection.
    page: false Integer|false
    The current page of the pagination. This parameter should be used in combination with the limit parameter.
    search: false String|false
    Filters the pagelist by a given search string. The string can contain multiple keywords separated by spaces. Only pages containing all given keywords get included in the pagelist.
    sort: false String|false
    Sorts the pagelist by a combination of a variable and order. Multiple combinations can be specified.
    For example sort: "date desc, title asc" will first sort all pages by date in descending order and then by title in ascending order. Setting this parameter to false will sort the pages by :basename asc.
    template: false String|false
    Filters the pagelist by template names matching a specified regex. Multiple templates can therefore be matched by using the | operator, like template: "page|home".
    type: false String|false
    Sets the pagelist type.

    Examples

    To get all pages of the first level and iterate over them, like a simple top navigation, you can use the following snippet:

    <@ newPagelist { 
        type: 'children', 
        context: '/' 
    } @>
    <@ foreach in pagelist @>
        <a href="@{ url }">@{ title }</a>
    <@ end @>
    

    A more complex example could be a search results page with filters and pagination.
    Note that it is possible to use query string parameters in the option array for dynamic filtering, searching and pagination (lines 3, 4 and 8).

    <@ newPagelist { 
        excludeHidden: false,
        filter: @{ ?filter }, 
        search: @{ ?search },
        sort: ':basename asc',
        template: 'documentation',
        limit: 10,
        page: @{ ?page | def (1) }
    } @>
    

    Filtering a pagelist by using the match option can be done as follows. Note that the JSON string is wrapped in single quotes.

    <@ newPagelist { 
        match: '{"url": "@{ regex }"}'
    } @>
    

    It is also possible to match pages by passing multiple regex patterns.

    <@ newPagelist { 
        match: '{"url": "@{ regex }", ":level": "/2/"}'
    } @>
    

    Related

    Pipe  ⁄
    match — Pipe

    Performs a Regex match and returns 1 if the given pattern matches and 0 if not.

    Pipe  ⁄
    replace — Pipe

    Performs a regular expression search and replace.

    Toolbox  ⁄
    filelist — Toolbox

    Updates the configuration of the filelist object. A foreach loop can be used to iterate over the files in the list. This method has no output.

    Toolbox  ⁄
    pagelist — Toolbox

    Modifies the currently defined pagelist pagelist object. Only specified options will be changed, all others will be preserved. To restore a default pagelist and reset all options, the newPagelist method can be used.

    Toolbox  ⁄
    queryStringMerge — Toolbox

    Creates a query string containing the specified paramters as key/value pairs merged with the existing query string of the current URL. This method can be used to create links for adding or replacing some parameters of the query string without touching the other ones. A standard ...

    Template Language  ⁄
    Objects — Template Language

    Objects in Automad are conceptually just lists containing iteratable items to be used in foreach loops. Such lists are automatically populated with default sets of elements while rendering a page. They always exist. The actual content of any object is depending on the current ...

    Objects  ⁄
    Pagelist — Objects

    The pagelist contains by default all pages which are not hidden and therefore has no defined type. Changing the pagelist type to one of the following available types will update the selection of pages accordingly. The main purpose of this object is to provide an easy way of ...

    Objects  ⁄
    Filelist — Objects

    The filelist contains by default all image files of the current page. The selection of files can be modified by using the filelist function. Check out this detailed example of how to use a filelist. Similar to the pagelist object, it is possible to get the number of files in the ...

    Objects  ⁄
    Tags — Objects

    The tags object contains all tags associated with the current page in the context. When iterating over the list of tags, the current tag can be adressed by using the :tag variable.

    Objects  ⁄
    Filters — Objects

    The filters object is a unique list of tags associated with pages of the current pagelist. A good example of the usage of the filters object can be found here. You can use the :filter variable to get the current filter tag while looping over the filters object.

    Control Structures  ⁄
    foreach — Control Structures

    The foreach loop iterates over objects. Depending of the type of the object in use, Automad provides different runtime variables within the code block of the loop to refer to items of the object. The :i variable refers to the index of the current iteration in the loop.

    Template Language  ⁄
    Recursive Navigations — Template Language

    Navigations and menus represent an essential part of any webiste. Automad provides convenient methods to iterate over the collection of pages recursively and therefore allows for creating site trees in a few simple steps. The basic concept behind a navigation tree in Automad is ...

    • Automad
    • Developer Guide
    • Building Themes
    • Template Language
    • Toolbox
    • newPagelist
    Discuss
    Packages
    Release Notes
    Support
    Terms of Use
      Become a Sponsor
      GitHub
      Twitter
      Facebook
      Instagram
      2013-2022 by Marc Anton Dahmen
    Released under the MIT license

    A faceless machine, creating one's portrait in the internet.
  • Automad
  • Getting Started
  • System
  • User Guide
  • Developer Guide
  • Headless Mode
  • Discuss
  • Packages
  • Developer Guide ←
  • Building Themes ←
  • Template Language ←
  • Toolbox
  • breadcrumbs
  • filelist
  • img
  • nav
  • navChildren
  • navSiblings
  • navTop
  • navTree
  • newPagelist
  • pagelist
  • queryStringMerge
  • redirect
  • set