Template variables

blog_page_path

Note: Only available within blog templates currently.

Get the page path of the blog root page. Example if you have a blog under https://www.example.com/locations/seattle/blog/ the blog_page_path would be /blog/

blog_root

Note: Only available within blog templates currently.

Get the URL of the blog root page. Includes the base_directory. Example if you have a blog under https://www.example.com/locations/seattle/blog/ the blog_root would be /locations/seattle/blog/

filter_posts

Get blog posts for the current site based on a supplied category slug. Note: Only available within blog templates currently.

<ul>
{% for post in filter_posts(category_slug='some-category-slug', limit=3) %}
    <li><a href="{{ post.url(**post_url_params) }}">{{ post.title }}</a></li>
{% endfor %}
</ul>

get_categories

Get list of all the current blog categories and links. Note: Only available within blog templates currently.

{% set categories = get_categories() %}
<ul>
{% for cat in categories %}
    <li><a href="{{ cat.url }}">{{ cat.name }}</a></li>
{% endfor %}
</ul>

Other available category values

ValueDescription

post_count

Total number of posts in that category (i.e 5)

slug

Slug of the category (i.e. some-category-name)

get_image

Utility for getting additional image details from an image ID

Initialize the image using the ID of the image.

{% set image = get_image(12345) %}

If an image is coming from custom_fields, you can access the ID value from an image using the field_name_id if the normal image path would have been field_name

Get an image path by size

{{ image.by_size('thumbnail') }}

This will return the full path the image that you can use in CSS or image tags/img/upload/image-name-here.thumbnail.jpg

For a list of available sizes, see:

Images and video

now

Python datetime object with properties of the current day and time.

Example of outputting the year (i.e. 2024)

<p>Copyright {{ now.year }}</p>

Available properties

  • now.year

  • now.month

  • now.day

  • now.hour

  • now.minute

strftime can be used to format the date. Format variables available here

Example of outputting YYYY-MM-DD

{{ now.strftime('%Y-%m-%d') }}

pages

This utility allows you to access and filter the current Pages within a Site.

Output all pages

<ul>
{% for p in pages %}
    <li>{{ p.full_path }}</li>
{% endfor %}
</ul>

Filtering pages

Example of filtering pages by template page type

<ul>
{% for p in pages.filter({'custom_page_type': 'promotions'}) %}
    <li>{{ p.full_path }}</li>
{% endfor %}
</ul>

Ordering pages

{{ pages.filter({}, order_by='path' }}

Accessing custom fields

{% for page in pages %}
    {{ page.custom_fields.some_value }}
{% endif %}

Get a single page

{% set home_page = pages.get_one({'path': '/'}) %}

Available page fields

Standard page fields used in templates

PropertyExample

name

Name of the current page

Home

full_path

Full page path which should be used for HTML links. If under a sub-directory, this path will contain the base_directory of the Local site/page

/local-page/about-us/

path

Page path set within the Site Builder. Good for looking up a particular page using filter or get_one

/about-us/

custom_page_type

Template page type

page_type_example

is_published

Boolean value if the page is currently published

True

is_indexed

Boolean value if the page is indexable. False would be returned if the Page is set to noindex or as a custom canonical setting on the Page

True

custom_fields

Array of custom field values. Access via custom_fields.value_name

pages.as_navigation

Utility for easily creating multi-level navigations for headers, footers and sidebars. Its setup to do recursive looping of items to support any depth of page navigations

Simple example - Full sitemap

Gets all the pages within the Site, then recursively outputs nested <ul> and <li> elements

<ul>
{% for item in pages.as_navigation(
  {'is_published': True}, order_by='name') recursive -%}
<li>
  <a href="{{ item.full_path }}">{{ item.name|safe }}</a>
  {%- if item.children %}
    <ul>{{ loop(item) }}</ul>
  {% endif %}
</li>
{% endfor %}
</ul>

Sidemenu example

Example of grabbing all pages based on a starting path, then outputting them with a headline. The item.depth == 0 is used to determine it is the first parent page (/services/) and then the subpages (/services/some-service/)are output in <ul>

You can also add additional differences in the output based on the depth by using item.depth

{% for item in pages.as_navigation(
  {'is_published': True, 'path__startswith': '/services/'}, order_by='name') recursive -%}

{% if item.depth == 0 %}
<div class="menu">
  <h2>{{ item.name }}</h2>
  {%- if item.children %}
  <div class="menu-items">
    <ul>{{ loop(item) }}</ul>
  </div>
  {% endif %}
</div>

{% else %}
<li>
  <a href="{{ item.full_path }}">{{ item.name|safe }}</a>
  {%- if item.children %}
    <ul>{{ loop(item) }}</ul>
  {% endif %}
</li>
{% endif %}

{% endfor %}

Last updated