Tweet

Docs /  configuration

Built-in Variables

Also see Avoiding Collisions

" Page " Variables

The following variables are defined on the page object, which exposes data for the "current page" at build time:

  • {{basename}} : Equivalent to node path.basename, returns the basename for the current page from the root of the context. Example: {{basename 'index.html'}}, returns "index", can also be used with the [page|Pages] variable: {{basename page}}.
  • {{dirname}} : equivalent to node path.dirname.
  • {{ext}} : equivalent to node path.extname.
  • {{extname}} : alias for ext
  • {{filename}} : equivalent to ( path.basename + path.extname ), {{filename 'index.html'}}, returns index.html. Can also be used with page variable: {{filename page}}.
  • {{pagename}} : alias for basename.
  • {{pageName}} : deprecated, use pagename or filename

" YFM " Variables

  • categories : a category, or an array of categories that are associated with this page. These should be provided in the yaml header.
  • tags : List of tag objects that are associated with this page. These should be provided in the yaml header.
  • custom : Any custom front matter that you specify will be available under page. For example, if you specify something: true in a page's front matter, that value will be available in templates as page.something"
  • layout : the layout to be used for the current page. Overrides any layouts defined in the assemble.options, at the task and target level,
  • published : Use published: false in the YAML Front Matter of a page to exclude the page from being rendered.
---
title: Just testing some stuff on this page, it should not be published
published: false
---

Collections

Collections can also be defined in YAML front matter:

  • pages : list of pages in a target.
  • categories : lists of all the category objects
  • tags : lists of all tag objects
  • paginate (planned)

Learn more about collections →

Custom variables

You may add any custom variable you require to the assemble task or target options. Custom variables are added to the root of the data context and be available in any templates.

For example, given that the custom variable production is set to false :

assemble: {
  options: {
    production: false 
  },
  ...
}

This template:

{{#if production}}
<script src="dist/assets/script.min.js"></script>
{{else}}
<script src="dist/assets/script.js"></script>
{{/if}}

Will render the HTML for the non-minified   script tag:

<script src="dist/assets/script.js"></script>

Helpers

Variables can be modified using using special tags called helpers. Helpers may also accept parameters, each of which is a Handlebars expression.

See Helpers and Custom Helpers


See the template for this page →

Find an error? Let us know →