jekyll/site/_posts/2012-07-01-variables.md

6.1 KiB
Raw Blame History

layout title prev_section next_section
docs Variables pages migrations

Jekyll traverses your site looking for files to process. Any files with YAML Front Matter are subject to processing. For each of these files, Jekyll makes a variety of data available to the pages via the Liquid templating system. The following is a reference of the available data.

Global Variables

Variable Description

site

Sitewide information + Configuration settings from _config.yml

page

This is just the YAML Front Matter with 2 additions: url and content.

content

In layout files, this contains the content of the subview(s). This is the variable used to insert the rendered content into the layout. This is not used in post files or page files.

paginator

When the paginate configuration option is set, this variable becomes available for use.

Site Variables

Variable Description

site.time

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

site.posts

A reverse chronological list of all Posts.

site.related_posts

If the page being processed is a Post, this contains a list of up to ten related Posts. By default, these are low quality but fast to compute. For high quality but slow to compute results, run the jekyll command with the --lsi (latent semantic indexing) option.

site.categories.CATEGORY

The list of all Posts in category CATEGORY.

site.tags.TAG

The list of all Posts with tag TAG.

site.[CONFIGURATION_DATA]

All variables set in your _config.yml are available through the site variable. For example, if you have url: http://mysite.com in your configuration file, then in your posts and pages it can be accessed using {{ "{{ site.url " }}}}. Jekyll does not parse changes to _config.yml in auto mode, you have to restart Jekyll to see changes to variables.

Page Variables

Variable Description

page.content

The un-rendered content of the Page.

page.title

The title of the Post.

page.url

The URL of the Post without the domain. e.g. /2008/12/14/my-post.html

page.date

The Date assigned to the Post. This can be overridden in a posts front matter by specifying a new date/time in the format YYYY-MM-DD HH:MM:SS

page.id

An identifier unique to the Post (useful in RSS feeds). e.g. /2008/12/14/my-post

page.categories

The list of categories to which this post belongs. Categories are derived from the directory structure above the _posts directory. For example, a post at /work/code/_posts/2008-12-24-closures.textile would have this field set to ['work', 'code']. These can also be specified in the YAML Front Matter.

page.tags

The list of tags to which this post belongs. These can be specified in the YAML Front Matter

ProTip™: Use custom front-matter

Any custom front matter that you specify will be available under page. For example, if you specify custom_css: true in a pages front matter, that value will be available in templates as page.custom_css.

Paginator

Variable Description

paginator.per_page

Number of posts per page.

paginator.posts

Posts available for that page.

paginator.total_posts

Total number of posts.

paginator.total_pages

Total number of pages.

paginator.page

The number of the current page.

paginator.previous_page

The number of the previous page.

paginator.next_page

The number of the next page.

Paginator variable availability

These are only available in index files, however they can be located in a subdirectory, such as /blog/index.html.