Learn

Global Variables

Statamic turns any variables set your _config folder’s YAML files into global variables. This allows you to use, as an example, {{ _site_root }} from your settings.yaml file in your templates. Variables prefixed with an underscore generally indicate they are also used by the system in some way.

Additionally, all the content fields of your current page are available as global-type variables. There are no loops needed to fetch your single page/entry variables. This means {{ title }}, {{ content }} and so on are available in your layouts as well, which makes setting meta tags a breeze.

All global variables can be used in conditionals without extra braces. Example: {{ if logged_in }}.

List of All Global Variables

_is_draft

Check if the page is hidden (as indicated by a double underscore in the filename)

_is_hidden

Check if the page is hidden (as indicated by a single underscore in the filename)

current_date

Display the current server date/time formatted by your _date_format setting. Accepts the format parameter.

current_url

The URL of your current page. Example: /about/team

environment

The name of your current environment if set.

homepage

The URL to your homepage. Example: /.

is_admin

Returns TRUE if the user is logged in with admin privileges.

is_{environment_name}

Where "{environment_name}" is the name of the environment you wish to check for. Useful in conditions. Example if is_dev.

last_modified

The last modified timestamp of the current page/entry. Accepts the format parameter.

last_segment

The last segment in your URL.

logged_in

returns TRUE/FALSE on whether the current user is logged in.

next

If on an entry page, the URL to the next entry.

now

The current timestamp, as in "right now"

page_url

The URL of your current page. Example: /about/team

permalink

The fully qualified URL of your current page. Example: http://example.com/about/team

prev

If on an entry page, the URL to the previous entry.

segment_x

Where "x" is any segment number. Returns the value of any given URL segment if present. Example: with a URL of /about/team/jack-london, segment_2 would return team.

taxonomy_name

If on a taxonomy URL returns the taxonomy name.

taxonomy_slug

If on a taxonomy URL returns the URL slug containing the taxonomy name.

theme_path

Path to your current theme: Example: _themes/denali/

username

If logged in, the username of the current user.

This article was last updated on September 13th, 2016. Find an error? Please let us know!