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.

If accessing posts outside blog templates, use get_posts

<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

get_menu

Load a website menu to use for rendering the menu as a navigation

{% set menu = get_menu('mainmenu') %}

Generating a menu tree

The menu from get_menu can be iterated over recursively to output a nested ul or other element for a navigation

<ul>
{% for item in get_menu('altmenu') recursive -%}
<li style="margin-left:20px;">
  <a {% if item.link %}href="{{ item.link }}"{% endif %}>{{ item.name|safe }} {{ item.depth }}</a>
  {%- if item.children %}
    <ul>{{ loop(item) }}</ul>
  {% endif %}
</li>
{% endfor %}
</ul>

Additional options

This option allows you to filter/search and generate a partial menu for a item with link matching the root_link

get_menu('altmenu', root_link='/services/heating/')

This can be used to grab part of a menu to use in a sidebar or other places without the need to create a separate menu within the template.

Note: the item.depth will still reflect the original depth within the entire menu.

get_posts

Get recent blog posts throughout Site pages.

Simple usage

{% for post in get_posts() %}
    <h2><a href="{{ post.external_url or post.link }}">{{ post.title }}</a></h2>
    <p>{{ post.date|datefmt(format='long') }}</p>
    {% if post.featured_img %}
        <p><img alt="{{ post.featured_img.alt or post.title }}" src="{{ post.featured_img.src }}" /></p>
    {% endif %}
    {% if post.excerpt %}
        <p>{{ post.excerpt }}</p>
    {% elif post.content %}
        <p>{{ post.content|striptags|truncatewords_html(75) }}</p>
    {% endif %}
{% endfor %}

Limiting the number of posts to return

Default is to return 5 posts

{% set posts = get_posts(limit=10) %}

Filtering posts by category

You will need to pass in the category_slug

{% set posts = get_posts(filters={'category_slug': 'some-category'}) %}

Multiple blog roots

If your template has multiple blog root pages (Example a Blog and a Press Releases section), you will need to pass in the Page path to the blog root so that it knows what type of posts to return.

{% set posts = get_posts(blog_root='/press-releases/')

Blog posts from a different Site

By default, get_posts will grab posts from the current Site. You and optionally provide a different Site ID to pull posts from.

Common use case for this is to pull Corporate blog posts into a Local site

{% set posts = get_posts(site_id=12345) %}

Filtering recent posts by location ID

You can pass in location_id, include_locationless as filters

{% set posts = get_posts(filters={'location_id': 12345 'include_locationless': True}) %}

Setting location_id will limit posts returned to those associated with a location. include_locationless will include posts that are associated with the set location_id AND posts that have no location association. include_locationless is only applied if a location_id is also provided.

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 %}

primary_location

Refers to the primary (first assigned) Location to a Site

<h2>Address</h2>
<p>
  {{ primary_location.street }}{% if primary_location.street2 %}{{ primary_location.street2 }}{% endif %}<br />
  {{ primary_location.city }}, {{ primary_location.state }} {{ primary_location.postal_code }}
</p>

If a Site does not have a Location assigned, this will return None

set_schema_overrides

Override and extend any existing schema blocks generated by DevHub. Note: this method will not validate the schema values you enter, so make sure you are adding valid Schema names and values to ensure Google and other search engines can properly read the schema.

Currently supports:

{% do set_schema_overrides('localbusiness', {
  'logo': 'https://www.someurl.com/logo.jpg'
}) %}

Last updated