In Jekyll, any liquid template file that contains a YAML front matter block will be processed by Jekyll. The front matter must be the first thing in the file (nothing before it) and must take the form of valid YAML declaration between triple-dashed lines. Inside front matter, you can define some variables (we call them page variables to separate with site variables that declared in the _config.yml file).

Here is a basic example of YAML front matter block:

---
layout: post
caption: "Introduction to Acegik Company"
---

Title here ...

Content here ...

In one of these variables, if you want it’s value refer to an earlier variable, site.title for example, you expect to place output markup Acegik’s Blog inside the string value as following:

---
layout: post
caption: "Introduction to {{ site.title }}"
---

<h1>{{ page.caption }}</h1>

Unfortunately, Jekyll will display exactly what you put in page variables. As a solution, you should create a simple Jekyll filter plugin which resolve the output markup into text, by expand nested liquid-variables in the YAML front matter.

# file: _plugins/expand_nested_variable_filter.rb

module Jekyll
  module ExpandNestedVariableFilter
    def flatify(input)
      Liquid::Template.parse(input).render(@context)
    end
  end
end

Liquid::Template.register_filter(Jekyll::ExpandNestedVariableFilter)

After that, you can apply this filter to your post:

---
layout: post
caption: "Introduction to {{ site.title }}"
---

<h1>{{ page.caption | flatify }}</h1>

Jekyll will process this file and render some output like “<h1>Introduction to Acegik Company</h1>”. The expansion works also for deeper nested structures - as long as the flatify filter is also specified on the inner liquid output-blocks.

Comments