Variables

Cobalt makes a variety of data available as Liquid variables.

This can be helpful for:

  • Theming
  • Easier maintenance for only having one place to update things

Example:

<html>
  <head>
    <title>{{ page.title }}</title>
  </head>
  <body>
  {{ page.content }}
  </body>
</html>

Global variables

VariableFormatDescription
siteObjectSite-wide information
pageObjectCurrent-page information
collectionObjectBuilt-in posts.

Site Variables

VariableFormatDescription
site.titleStringThe title of the entire site, see _cobalt.yml.
site.descriptionStringThe description of the entire site, see _cobalt.yml.
site.base_urlStringThe URL of your site, see _cobalt.yml. This is helpful for making absolute URLs, particularly when run within cobalt serve.
site.dataObjectThe merged result of data files in the _data directory and site: data in _cobalt.yml.
site.timeDateTimeA liquid_core::model::DateTime representing the time of the website re-generation.

Page Variables

In the context of your page content:

VariableFormatDescription
page.permalinkStringRelative path to the page, see frontmatter.
page.titleStringThe title of the page, see frontmatter.
page.slugStringThe identifier of the page, see frontmatter.
page.descriptionStringThe description of the page, see frontmatter.
page.categoriesList of StringsHierarchical categories this page lives under, see frontmatter.
page.published_dateYYYY-MM-DD HH:MM:SS TZThe date the page was initially published, see frontmatter.
page.is_draftBooleanSee frontmatter.
page.file.permalinkStringRelative path to the source file.
page.collectionStringThe slug of the page's collection. "posts" for posts.
page.dataObjectUser-defined data, see frontmatter.
page.nextObjectPage variables of the next page in the collection. Only available in posts
page.previousObjectPage variables of the previous page in the collection. Only available in posts

Additionally, in the context of your page layout:

VariableFormatDescription
page.contentStringThe rendered page content (i.e. excludes the layout).
page.excerptStringThe rendered excerpt of a page, see excerpt / excerpt_separator.

Collection Variables

Below, the built-in posts collection is demonstrated.

VariableFormatDescription
collections.posts.titleStringThe title of the posts collection, see _cobalt.yml.
collections.posts.descriptionStringThe description of the posts collection, see _cobalt.yml.
collections.posts.slugStringThe identifier of the posts collection, see _cobalt.yml.
collections.posts.rssStringThe permalink for the posts' RSS feed, see _cobalt.yml and RSS.
collections.posts.jsonfeedStringThe permalink for the posts' RSS feed, see _cobalt.yml.