Custom Variables in Jekyll Front Matter

jekyll

New to Jekyll and wondering if it's possible to include custom variables in Jekyll Front Matter. It would be useful for nested layouts, for example something like:

layouts/artist.html

----
layout: default
title: {{ page.artist }} (Artist)
----

I get an error trying that.

Best Solution

At the moment, Jekyll do not support Liquid variables in the front matter, and the only way to do that would be through a plugin, such as jekyll-conrefifier.


Alternatively, what you can do, though, is create variables that you re-use on the same file:

{% assign new_title = page.title | append: " (Artist)" %}
<h1>{{ new_title }}</h1>

and you can also pass variables to files that get included. For example, including a file from _includes\display-post.html passing the modified title as an argument:

{% assign new_title = page.title | append: " (Artist)" %}
{% include display-post.html post_title=new_title %}

And then getting the value of the value passed in (example content of _includes\display-post.html):

{% assign title_received = include.post_title %}

<h1>Title that as passed in: {{ title_received }}</h1>
Related Question