HomeArticles

Jekyll filter: Use Liquid in front-matter

Stefan Baumgartner

Stefan on Mastodon

More on Jekyll

Jekyll’s template language Liquid is pretty powerful. We especially use Liquid objects to access different data across all pages, like


{{ site.data.placeholder.product-name }}

instead of the product name itself. However, we can’t use these objects in front-matter, where we would define titles and other meta information:


---
title: How to install {{ site.data.placeholder.product-name }}
---

Not possible. Well, not without a little help at least. Here’s a nice filter that parses Liquid objects when used within Jekyll front-matter:

module LiquidFilter
def liquify(input)
Liquid::Template.parse(input).render(@context)
end
end
Liquid::Template.register_filter(LiquidFilter)

Use it with


{{ page.title | liquify }}

Anywhere in your layouts.

More articles on Jekyll

Stay up to date!

3-4 updates per month, no tracking, spam-free, hand-crafted. Our newsletter gives you links, updates on fettblog.eu, conference talks, coding soundtracks, and much more.