Variables and Filters

There are variables and filters exposed to the templates that you have access to.

Variables

meta

Metadata of the Pagedip being used in the render.

  • guid - the Pagedip's unique identifier

  • options - theme options for the Pagedip

  • title - the title of the Pagedip

  • handle - the URL handle

  • owner - the Pagedip owner's username

page

The page document being used in the render.

  • _id - The current page's unique identifier

  • title - The page title

  • path - The page's relative path from the Pagedip's base URL.

  • order - The order in which the page appears in the table of contents

  • options - Theme options set for this page

theme

Metadata of this theme.

  • _id - The theme's unique identifier

  • title - The theme's title

  • handle - The theme's handle

  • description - A description of the theme

  • preview - Path to a preview Pagedip, shown when selecting a theme within Pagedip.

  • blueprint - Theme options that can be set on a page-to-page basis

  • globalBlueprint - Theme options set globally in the Pagedip's settings page

  • blockStyles - An array of custom styles for block elements

template

Metadata of this template.

  • _id - Template's unique identifier

  • cname - The templates's unique name

  • title - The template's title

  • filepath - The path the the template's source file

  • layout - The layout template that this template is rendered within

  • blueprint - Theme options for this template

pages

An array of page documents for every page in the current Pagedip.

contents

An array of content document for this page. This isn't necessary to use, as the render process will forcefully inject the contents into the proper pd-editable elements.

Each individual content document has the following fields:

  • _id - The content's unique identifier

  • name - The content name, pairs with the pd-editable field that it will be rendered into

  • value - the content's value

  • type - The content type

getUrl()

A function that returns the current Pagedip's url, which is distinctly different from the page's URL. You can pass additional path parts to the function to add them to the end. To get the current page's URL, use {{ getUrl(page.handle) }}.

inEdit

A boolean signifying if the current environment is in the Pagedip editor or live. This can be helpful for WYSIWYG specific styling and content.

Theme and Template Options

All data from the theme, template, and embed blueprints are passed into the templates as variables. Properties on these objects can be accessed with dot notation or bracket syntax.

{{ options.options_group_name.option_name }}
{{ options["options_group_name"]["option_name"] }}

Nunjucks Filters

file

Converts a local asset name into the full URL. This is necessary for including assets in a template. The path given to file is relative to the assets directory set by the directories.assets field in the theme.json.

style

Wraps a URL in a <link> tag.

script

Wraps a URL in a <script> tag.

Example Usage:

<html>
 <head>
  // wrap a URL in a <link> tag:
  {{ 'http://cdn.example.com/fonts.css' | style }}

  // wrap a URL in a <script> tag:
  {{ 'http://cdn.example.com/jquery.js' | script }}

  // convert local asset names into full URLs
  // and wrap them in a <script> or <link> tag:
  {{ 'main.css' | file | style }}
  {{ 'index.js' | file | script }}
 </head>
 <body>
  // convert local asset into full URL
  <img src="{{ 'images/my-image.png' | file }}" /> ... 
 </body>
</html>

Nunjucks builtin filters are also available.