Skip to main

Page Filters

src/filters/pages.js


Status

isPublic()

Check that a page is

Params:

  • page {11ty page object}

isCurrent()

Check that the page does not have an end date

Params:

  • page {11ty page object}

Filter

getCurrent()

Filter to pages that do not have an end date

Params:

  • collection {array}

    containing 11ty page objects

getPublic()

Return only the public pages from a collection

Params:

  • collection {array}

    containing 11ty page objects

hasData()

Return true if a an object (often a page) has particular data

Params:

  • obj {object}

    The object to search for data

  • keys {string}

    Any nested data attributes to get

  • value {any}

    Only approve pages where the desired attributes have a given value

  • exact {boolean}

    Force an exact match, rather than inclusion

withData()

Return pages with particular data

Params:

  • collection {array}

    containing 11ty page objects

  • keys {string}

    Any nested data attributes to get

  • value {any}

    Only get pages where the desired attributes have this value

  • exact {boolean}

    Force an exact match, rather than inclusion

removePage()

Remove any one page from a collection (especially for removing tag index pages from their own resource list)

Params:

  • collection {array}

    containing 11ty page objects

  • url {url}

    URL of the page to remove

Data

getData()

Return combined data from a collection

Params:

  • collection {array}

    often an array of 11ty pages, but can be an array of any objects

  • keys {string | false}

    use dot-notation (data.press) for nested keys, or false to filter without digging into nested data

  • test {string | object} = undefined

    filter the resulting collection

Example:

{# all events #}
{{ collections.all | getData('data.events') }}
{# all events with a venue #}
{{ collections.all | getData('data.events', 'venue') }}
{# all events with a venue of 'Smashing Conf' #}
{{ collections.all | getData('data.events', {'venue': 'Smashing Conf'}) }}

findData()

The same as getData, but only returns the first match in the collection

Params:

  • collection {array}

    often an array of 11ty pages, but can be an array of any objects

  • keys {string}

    use dot-notation (data.press) for nested keys

  • test {string | object} = undefined

    filter the resulting collection

Example:

{{ collections.all | findData('data.press', {'slug': 'handoff'}) }}

getPage()

Return a single page by url, or return data from inside that page

Params:

  • collection {array}

    often an array of 11ty pages, but can be an array of any objects

  • url {string}

    The url of the desired page

  • keys {string}

    use dot-notation (data.press) for nested keys

  • test {string | object} = undefined

    filter the resulting collection

Example:

{{ collections.all | getPage('/work/timedesigner/', 'data.press') }}

findPage()

Find the first page with any particular data

Params:

  • collection {array}

    often an array of 11ty pages, but can be an array of any objects

  • keys {string}

    use dot-notation (data.press) for nested keys

  • value {any}

    Only find pages where the desired keys have a given value

Example:

{{ collections.all | findPage('data.cta_slug', 'workshop') }}

Sorting

pageYears()

Add sort and year keys to the page object, based on the latest date available (date or end), optionally including dates from events

Params:

  • collection {array}

    containing 11ty page objects

eventSort()

Sort pages based on either the page date, or the most recently past event date.

Params:

  • collection {array}

    containing 11ty page objects

byYear()

Runs a collection through pageYears, and then groups them by the resulting year value

Params:

  • collection {array}

    containing 11ty page objects


See Also: