Sitemap Pages API
The Sitemap Pages API is a convenience method that returns only the regular pages on the site. No app pages are returned at all.
It's equivalent to calling _api.sitemap.get('page').
The return value from the API call will always be an array of pages. Because of that, you will almost always assign the API result to a variable.
The pages that are returned include any regular pages that are configured to be included in the sitemap.
{% set pages = _api.sitemap.pages() %}
Below is a sample of the data returned by the API.
Array
(
[0] => Array
(
[url] => /
[name] => Home Page
[app] => page
[appInstance] => page
[appSection] => page
[updatedOn] => 1613675468
[id] => 1
[changeFrequency] => monthly
[priority] => 0.5
[breadcrumb] => Page breadcrumb text
[title] => Page SEO title
)
[1] => Array
(
[url] => /ads
[name] => Ads
[app] => page
[appInstance] => page
[appSection] => page
[updatedOn] => 1610112561
[id] => 46
[changeFrequency] => monthly
[priority] => 0.5
)
[2] => Array
(
[url] => /another-page
[name] => Another Page
[app] => page
[appInstance] => page
[appSection] => page
[updatedOn] => 1607974598
[id] => 108
[changeFrequency] => monthly
[priority] => 0.5
)
[3] => Array
(
[url] => /company
[name] => About Us
[app] => page
[appInstance] => page
[appSection] => page
[updatedOn] => 1607974598
[id] => 23
[changeFrequency] => monthly
[priority] => 0.5
[children] => Array
(
[0] => Array
(
[url] => /company/team
[name] => Our Team
[app] => page
[appInstance] => page
[appSection] => page
[updatedOn] => 1559244017
[id] => 79
[changeFrequency] => monthly
[priority] => 0.5
)
[1] => Array
(
[url] => /company/history
[name] => Our History
[app] => page
[appInstance] => page
[appSection] => page
[updatedOn] => 1559244017
[id] => 89
[changeFrequency] => monthly
[priority] => 0.5
)
)
)
)
Example
Below is an example showing how to use this API to build an unordered list of pages for a sitemap page. Because pages can have child pages, this uses a macro to handle recursively building the list of pages.
{% macro buildSitemap(pages) %}
<ul>
{% for page in pages %}
<li><a href="{{ page.url }}">{{ page.name }}</a> (Last updated on {{ page.updatedOn|date('F j, Y \\a\\t g:i a') }})
{% if page.children %}
{% import _self as macros %}
{{ macros.buildSitemap(page.children) }}
{% endif %}
</li>
{% endfor %}
</ul>
{% endmacro %}
{% import _self as macros %}
{% set pages = _api.sitemap.pages() %}
{% if pages|length > 0 %}
{{ macros.buildSitemap(pages) }}
{% endif %}
Page Data
The information included for each page includes:
- url - The URL for the page
- name - The page name
- app - The app name (for Pages it is "page")
- appInstance - Pages don't have app instances, but for consistency sake it's included. (For Pages it is "page")
- appSection - Pages don't have app sections, but for consistency sake it's included. (For Pages it is "page")
- updatedOn - The numerical timestamp of when the page was last updated. Use the date filter to format the date.
- id - The page id
- changeFrequency - The sitemap.xml change frequency value
- priority - The sitemap.xml priority value