6.0 KiB
title | permalink | redirect_from |
---|---|---|
Front Matter | /docs/front-matter/ | /docs/frontmatter/index.html |
Any file that contains a YAML front matter block will be processed by Jekyll as a special file. The front matter must be the first thing in the file and must take the form of valid YAML set between triple-dashed lines. Here is a basic example:
---
layout: post
title: Blogging Like a Hacker
---
Between these triple-dashed lines, you can set predefined variables (see below for a reference) or even create custom ones of your own. These variables will then be available to you to access using Liquid tags both further down in the file and also in any layouts or includes that the page or post in question relies on.
UTF-8 Character Encoding Warning
If you use UTF-8 encoding, make sure that no BOM
header
characters exist in your files or very, very bad things will happen to
Jekyll. This is especially relevant if you’re running
Jekyll on Windows.
ProTip™: Front Matter Variables Are Optional
If you want to use Liquid tags and variables but don’t need anything in your front matter, just leave it empty! The set of triple-dashed lines with nothing in between will still get Jekyll to process your file. (This is useful for things like CSS and RSS feeds!)
Predefined Global Variables
There are a number of predefined global variables that you can set in the front matter of a page or post.
Variable | Description |
---|---|
|
|
ProTip™: Render Posts Marked As Unpublished
To preview unpublished pages, run `jekyll serve` or `jekyll build` with the `--unpublished` switch. Jekyll also has a handy drafts feature tailored specifically for blog posts.
Custom Variables
You can also set your own front matter variables you can access in Liquid. For
instance, if you set a variable called food
, you can use that in your page:
{% raw %}
---
food: Pizza
---
<h1>{{ page.food }}</h1>
{% endraw %}
Predefined Variables for Posts
These are available out-of-the-box to be used in the front matter for a post.
Variable | Description |
---|---|
|
A date here overrides the date from the name of the post. This can be
used to ensure correct sorting of posts. A date is specified in the
format |
|
|
ProTip™: Don't repeat yourself
If you don't want to repeat your frequently used front matter variables over and over, define defaults for them and only override them where necessary (or not at all). This works both for predefined and custom variables.