Skip to main content
Documentation Configuration

Variables

Bridgetown makes a variety of data available to templates. Files with front matter are subject to processing during the static generation process, and you can also use many of the same objects in dynamic routes as well.

The following is an overview of commonly-available data. We also have a Ruby API Reference available.

Global Variables #

Variable Description

site

Site wide information + configuration settings. See below for details.

resource

Resource front matter and other content. Custom variables set via the front matter will be available here. See below for details.

layout

Layout specific information + the front matter. Custom variables set via front matter in layouts will be available here.

yield (Ruby), content (Liquid)

In layout files, the rendered content of the resource being wrapped. Not defined in resource files themselves.

environment / env

The deployment environment (development, production, etc.) is obtained from the Bridgetown instance Bridgetown.environment (or Bridgetown.env) in Ruby templating and bridgetown.environment in Liquid.

Site Variables #

Variable Description

site.time

The current time (when you run the bridgetown command).

site.resources

A list of all resources (from pages, posts and other collections).

site.static_files

A list of all static files (i.e. files not processed by Bridgetown's converters or the Liquid renderer). Each file has five properties: path, modified_time, name, basename and extname.

site.collections

A list of all the collections (including posts).

site.data

A list containing the data loaded from the YAML files located in the _data directory.

site.categories.CATEGORY

The list of all resources in category CATEGORY.

site.tags.TAG

The list of all resources with tag TAG.

site.config.url (Ruby) / site.url (Liquid)

Contains the url of your site as configured (for example, url "http://mysite.com"). For the development environment there is an exception: site.config.url will be set to the value of your localhost, as if you had manually configured url "http://localhost:4000".

site.metadata

You can put metadata variables in _data/site_metadata.yml so they'll be easy to access and will regenerate pages when changed. This is a good place to put <head> content like site title, description, icon, social media handles, etc. Then you can reference site.metadata.title, etc. in your templates.

site.config.[KEY] (Ruby) / site.[KEY] (Liquid)

All the variables set via the command line and your configuration are available through the site.config variable. For example, if you have foo "bar" in your initializer, then it will be accessible site.config.foo (or site.foo in Liquid). Bridgetown does not parse changes to config files during live reload—you must restart Bridgetown to see changes to variables.

Resource Variables #

Variable Description

resource.content

The content of the resource (Markdown, HTML, etc.).

resource.summary

An excerpt of the resource from the configured summary service.

resource.relative_url

The URL of the resource without the domain, but with a leading slash, e.g. /2008/12/14/my-post/

resource.date

The Date assigned to the resource. This can be overridden in front matter by specifying a new date/time in the format YYYY-MM-DD HH:MM:SS (assuming UTC), or YYYY-MM-DD HH:MM:SS +/-TTTT (to specify a time zone using an offset from UTC. e.g. 2008-12-14 10:30:00 +0900).

resource.id

An identifier unique to the resource and its collection (useful in RSS feeds). e.g. repo://posts.collection/2021-10-05-my-post.md

resource.data.categories

The list of categories to which the resource belongs, which can be specified in the front matter.

resource.data.tags

The list of tags to which the resource belongs. These can be specified in the front matter.

resource.taxonomies

Access a more comprehensive list of taxonomy objects including custom taxonomies.

resource.relations

Other resources related to this one if you have relations set up.

resource.collection

The collection to which this resource belongs. Information on collection variables here.

resource.relative_path

The path of the resource relative to the source folder.

resource.next

The next resource relative to the position of the current resource in its collection. Returns nil for the last entry.

resource.previous

The previous resource relative to the position of the current resource in its collection. Returns nil for the first entry.

Using Custom Front Matter

Any custom front matter that you specify will be available under resource. For example, if you specify custom_css: true in a resource’s front matter, that value will be available as resource.data.custom_css.

If you specify front matter in a layout, access that via layout. For example, if you specify class: full_page in a layout’s front matter, that value will be available as layout.data.class in the layout.

Server-Rendered Routes