# How do you make Jekyll execute Liquid variables in front matter

**URL:** <https://talk.jekyllrb.com/t/how-do-you-make-jekyll-execute-liquid-variables-in-front-matter/1638>\
**Category:** Help\
**Created:** [March 27, 2018, 8:40am UTC](https://talk.jekyllrb.com/t/how-do-you-make-jekyll-execute-liquid-variables-in-front-matter/1638 "2018-03-27T08:40:26Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![kblife](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/kblife/32/870_2.png) [@kblife](https://talk.jekyllrb.com/u/kblife)\
**Post date:** [March 27, 2018, 8:40am UTC](https://talk.jekyllrb.com/t/how-do-you-make-jekyll-execute-liquid-variables-in-front-matter/1638/1 "2018-03-27T08:40:26Z")

</div>

Hi, I’m trying to call Liquid values into my layout/include front matter. But usually Jekyll outputs it raw without executing it.

Say I got

```auto
---
title: Welcome to {{ site.title }}
---

```

I’d expect the output to be “Welcome to My Website”; instead I get “Welcome to {{ site.title }}”, meaning the Liquid tag isn’t executed.

Is there a way to get this done?

Thanks.

---

<div class="post-metadata">

**Author:** ![rdyar](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rdyar/32/710_2.png) [@rdyar](https://talk.jekyllrb.com/u/rdyar)\
**Post date:** [March 27, 2018, 4:19pm UTC](https://talk.jekyllrb.com/t/how-do-you-make-jekyll-execute-liquid-variables-in-front-matter/1638/2 "2018-03-27T16:19:49Z")

</div>

Pretty sure liquid is not allowed in the front matter.

---

<div class="post-metadata">

**Author:** ![kblife](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/kblife/32/870_2.png) [@kblife](https://talk.jekyllrb.com/u/kblife)\
**Post date:** [March 28, 2018, 8:28am UTC](https://talk.jekyllrb.com/t/how-do-you-make-jekyll-execute-liquid-variables-in-front-matter/1638/3 "2018-03-28T08:28:31Z")

</div>

So, I wonder is this a bug or a feature…and I’m really curious to find a way around it because it’s increasingly becoming a need for my use cases…it’s why I posted it here in such detail…

---

<div class="post-metadata">

**Author:** ![rdyar](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rdyar/32/710_2.png) [@rdyar](https://talk.jekyllrb.com/u/rdyar)\
**Post date:** [March 28, 2018, 3:53pm UTC](https://talk.jekyllrb.com/t/how-do-you-make-jekyll-execute-liquid-variables-in-front-matter/1638/4 "2018-03-28T15:53:42Z")

</div>

I think it is intended behavior based on the order of how things are render would be my guess.

Your example is very simple, is there something else you are trying to accomplish? for example, if you are using title for the Title in the Head, then you can use an include and use liquid there to insert the site.title.

First answer here has a clever solution that may work:

> <https://stackoverflow.com/questions/14487110/include-jekyll-liquid-template-data-in-a-yaml-variable>

---

<div class="post-metadata">

**Author:** ![kblife](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/kblife/32/870_2.png) [@kblife](https://talk.jekyllrb.com/u/kblife)\
**Post date:** [March 28, 2018, 5:11pm UTC](https://talk.jekyllrb.com/t/how-do-you-make-jekyll-execute-liquid-variables-in-front-matter/1638/5 "2018-03-28T17:11:11Z")

</div>

Thanks, @rdyar, so this Liquid’s `replace` filter method did work in exactly the same way as used, with `!SITE.URL!`. I supposed I can try it with other variables, too. But I just wish there was a way to get around it automatically…

I mean, at ease, I’d love to just drop variable calls/placeholders even while in front matter…

---

<div class="post-metadata">

**Author:** ![rdyar](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rdyar/32/710_2.png) [@rdyar](https://talk.jekyllrb.com/u/rdyar)\
**Post date:** [March 28, 2018, 6:58pm UTC](https://talk.jekyllrb.com/t/how-do-you-make-jekyll-execute-liquid-variables-in-front-matter/1638/6 "2018-03-28T18:58:14Z")

</div>

yeah, that was hacky but outside the box thinking.

I’m sure others would like the same thing, but I’m guessing it is not easy to accomplish.

---

<div class="post-metadata">

**Author:** ![erinkcochran](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/erinkcochran/32/918_2.png) [@erinkcochran](https://talk.jekyllrb.com/u/erinkcochran)\
**Post date:** [April 2, 2018, 2:08pm UTC](https://talk.jekyllrb.com/t/how-do-you-make-jekyll-execute-liquid-variables-in-front-matter/1638/7 "2018-04-02T14:08:35Z")

</div>

While Liquid isn’t allowed in Frontmatter out of the box, there’s a fairly simple plugin you can use to get around this. [This blog post](http://acegik.net/blog/ruby/jekyll/plugins/howto-nest-liquid-template-variables-inside-yaml-front-matter-block.html) contains examples and the code you need, but all you need to do is add a Liquid filter to your variables to output the actual variables of the thing you’re referencing.

For your example, this won’t work to render the actual title (the one displayed as the title of a tab in a browser, etc), but it will work for rendering content on the pages themselves. For example:

```auto
_config.yml:

title: "My Website"

index.html:
---
title: "Welcome to {{ site.title }}"
---

{{ page.title | flatify }}

```

This would output `Welcome to My Website`.

It isn’t perfect, but I’ve found this to be really helpful overall!

---

<div class="post-metadata">

**Author:** ![kblife](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/kblife/32/870_2.png) [@kblife](https://talk.jekyllrb.com/u/kblife)\
**Post date:** [April 7, 2018, 4:48am UTC](https://talk.jekyllrb.com/t/how-do-you-make-jekyll-execute-liquid-variables-in-front-matter/1638/8 "2018-04-07T04:48:06Z")

</div>

Thanks, @erinkcochran I’ll take a look at the post, implement the suggested plugin and hope it works…is this something Jekyll could consider making possible within its core in future?

Thanks.

---

<div class="post-metadata">

**Author:** ![kblife](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/kblife/32/870_2.png) [@kblife](https://talk.jekyllrb.com/u/kblife)\
**Post date:** [April 7, 2018, 4:58am UTC](https://talk.jekyllrb.com/t/how-do-you-make-jekyll-execute-liquid-variables-in-front-matter/1638/9 "2018-04-07T04:58:52Z")

</div>

O, my God, finally a solution that worked, nifty! Thanks very much @erinkcochran

 ![23](https://canada1.discourse-cdn.com/flex030/uploads/jekyllrb/original/1X/e6d28fcf2107376afb1072459075309f4e910e34.png)

 ![07](https://canada1.discourse-cdn.com/flex030/uploads/jekyllrb/original/1X/84533b421fbb3f1f1be48f15235906196e8916b2.png)

 ![14](https://canada1.discourse-cdn.com/flex030/uploads/jekyllrb/original/1X/d28600ccc346795f829c752b5951efb9b7ac26f0.png)

 ![51](https://canada1.discourse-cdn.com/flex030/uploads/jekyllrb/original/1X/c939b4a4aedfcd398f91d9ecfed9920da950f087.png)

---

<div class="post-metadata">

**Author:** ![erinkcochran](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/erinkcochran/32/918_2.png) [@erinkcochran](https://talk.jekyllrb.com/u/erinkcochran)\
**Post date:** [April 11, 2018, 5:53pm UTC](https://talk.jekyllrb.com/t/how-do-you-make-jekyll-execute-liquid-variables-in-front-matter/1638/10 "2018-04-11T17:53:08Z")

</div>

You’re welcome! It’d be super if the Jekyll team would implement it within the core. An issue was recently opened on the repo that asks for this to be a core feature - [go pile on](https://github.com/jekyll/jekyll/issues/6815)!

---

<div class="post-metadata">

**Author:** ![mhagnumdw](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mhagnumdw/32/1028_2.png) [@mhagnumdw](https://talk.jekyllrb.com/u/mhagnumdw)\
**Post date:** [May 27, 2018, 2:44pm UTC](https://talk.jekyllrb.com/t/how-do-you-make-jekyll-execute-liquid-variables-in-front-matter/1638/11 "2018-05-27T14:44:58Z")

</div>

@erinkcochran

This not work for me. I’m using jekyll 3.8.2. Any suggestions? Tks.

---

<div class="post-metadata">

**Author:** ![kblife](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/kblife/32/870_2.png) [@kblife](https://talk.jekyllrb.com/u/kblife)\
**Post date:** [May 27, 2018, 3:57pm UTC](https://talk.jekyllrb.com/t/how-do-you-make-jekyll-execute-liquid-variables-in-front-matter/1638/12 "2018-05-27T15:57:08Z")

</div>

Interesting. Why not, though, can you share snippets of your code, perhaps where you feel the issue may be coming from? I’d be glad to take a look.

---

<div class="post-metadata">

**Author:** ![mhagnumdw](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mhagnumdw/32/1028_2.png) [@mhagnumdw](https://talk.jekyllrb.com/u/mhagnumdw)\
**Post date:** [May 27, 2018, 4:37pm UTC](https://talk.jekyllrb.com/t/how-do-you-make-jekyll-execute-liquid-variables-in-front-matter/1638/13 "2018-05-27T16:37:57Z")

</div>

@kblife @erinkcochran  
Sorry, this work for me too! I forgot “| flatify”

---

<div class="post-metadata">

**Author:** ![erinkcochran](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/erinkcochran/32/918_2.png) [@erinkcochran](https://talk.jekyllrb.com/u/erinkcochran)\
**Post date:** [February 27, 2019, 3:15pm UTC](https://talk.jekyllrb.com/t/how-do-you-make-jekyll-execute-liquid-variables-in-front-matter/1638/15 "2019-02-27T15:15:36Z")

</div>

@bmr It looks like your post was withdrawn - did you manage to figure out the issue? I’m happy to help if I can!

---

<div class="post-metadata">

**Author:** ![ashkan-nasirzadeh](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/ashkan-nasirzadeh/32/2186_2.png) [@ashkan-nasirzadeh](https://talk.jekyllrb.com/u/ashkan-nasirzadeh)\
**Post date:** [January 23, 2020, 1:07pm UTC](https://talk.jekyllrb.com/t/how-do-you-make-jekyll-execute-liquid-variables-in-front-matter/1638/16 "2020-01-23T13:07:06Z")

</div>

PLEASE HELP  
i have a front matter:

```
---
sjcm: "{{ site.data.para1.para2 }}"
---

```

actually that is a json and i want to access that json so:  
`{{ page.sjcm | flatify }}`

this gives me sth like:

> {“a”: “b”,“c”:“d”}{“e”:“f”,“g”:“h”}

but i cant iterate on it due to lack of `","` because what i want and what really is in file is:

> {“a”: “b”,“c”:“d”} **,** {“e”:“f”,“g”:“h”}

tnx for help

---

<div class="post-metadata">

**Author:** ![rdyar](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rdyar/32/710_2.png) [@rdyar](https://talk.jekyllrb.com/u/rdyar)\
**Post date:** [January 24, 2020, 1:27am UTC](https://talk.jekyllrb.com/t/how-do-you-make-jekyll-execute-liquid-variables-in-front-matter/1638/17 "2020-01-24T01:27:21Z")

</div>

one thing at a time… you can’t use liquid in the front matter by default, above they are using a plugin. Are you using that?

as for the json issue, if you think the liquid filter is doing something wrong I would make a new post just for that with a minimal example of how to test it.

---

<div class="post-metadata">

**Author:** ![ashkan-nasirzadeh](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/ashkan-nasirzadeh/32/2186_2.png) [@ashkan-nasirzadeh](https://talk.jekyllrb.com/u/ashkan-nasirzadeh)\
**Post date:** [January 25, 2020, 12:35pm UTC](https://talk.jekyllrb.com/t/how-do-you-make-jekyll-execute-liquid-variables-in-front-matter/1638/18 "2020-01-25T12:35:53Z")

</div>

tnx rdyar, yes i’m using that plugin and its very useful but not in my case!  
actually that plugin is useful when you want to move an stringed-variable to frontmatter, but what i want is different , i want to use a specific json file to iterate on and automatically make a post layout with that which it’s address is site.data.para1.para2 and it should be given in frontmatter **but the json i get from front matter seems stringifed and its not iterable!**

---

<div class="post-metadata">

**Author:** ![meldarionqeusse](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/meldarionqeusse/32/4679_2.png) [@meldarionqeusse](https://talk.jekyllrb.com/u/meldarionqeusse)\
**Post date:** [May 26, 2022, 11:40am UTC](https://talk.jekyllrb.com/t/how-do-you-make-jekyll-execute-liquid-variables-in-front-matter/1638/19 "2022-05-26T11:40:46Z")

</div>

Hi, I am new to jekyll but I quickly ran into the desire to have liquid variable in the front matter and I stumbles on this which worked for the title and other variable. However I would like o flatify the date and it’s giving me an error I am presuming because of the % sign in column 48 of line 4. I am not sure if I need escape the quotes or % sign or how to escape them (I tried to escape with \ and it still gave me an error)

```auto
---
layout: post
title: Test
caption: "{{site.images}}{{ page.date | date: "%Y%m%d" }}_"
---

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

```

error:

```auto
          Error: YAML Exception reading /home/test/Documents/websites/websitename/_posts/2022-05-26-1.md: (<unknown>): found character that cannot start any token while scanning for the next token at line 4 column 48

```

Some background about what I am trying to accomplish. Instead of naming my post I am just giving them a name like `2022-05-26-1.md` and then name them using the `title:` in the front matter. If I need to attach an image I just put the image in the /assets/img folder with the name of the date `20220526_1.jpg`. Then in the text where I need to use the image I just write `![img]({{ page.caption | flatify}}_1.jpg)`
