Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jekyll / Liquid include files dynamically

currently I'm working on a new site with Jekyll and have some kind of problem there. I have a layout page, where I can define the background image with variables from each page.

Layout:

class="background background-{{ page.header_bg }}"

Page:

---
header_bg: storm
---

But now I want to include some file dynamically, depending on the variable value. Well, I can do it with some if or case statements, but actually I want to do something like

{% include page.header_bg %}

But this does not work, because Jekyll is looking for a file, that is called "page.header_bg" and not the value.

Can some one help me please?

like image 850
user39063 Avatar asked May 08 '14 12:05

user39063


1 Answers

According to the docs, you need to put the variable name inside additional {{ }}.

Quote from the link:

ProTip™: Use variables as file name

The name of the file you wish to embed can be literal (as in the example above), or you can use a variable, using liquid-like variable syntax as in {% include {{my_variable}} %}.

like image 104
Christian Specht Avatar answered Oct 11 '22 15:10

Christian Specht