NewbornCodeMonkey
NewbornCodeMonkey

Reputation: 198

Jekyll include variables from external file

With Jekyll, I know you can include a variable in the include line, like so:

---
layout: default
testVar: test1
---
{% include test_block.html testDivContent=page.testVar %}

Is it possible to include another file that passes in the variable content (in this case testVar: test1) from an external file?

So something like

---
layout: default
---
{% include testVar_file.html %}
{% include test_block.html testDivContent=page.testVar %}

Where testVar_file.html contains the variable testVar: test1

Upvotes: 2

Views: 592

Answers (1)

Zombo
Zombo

Reputation: 1

You can use a data file.

_data/testVar_file.yml

testVar: test1

index.md

---
layout: default
---
{% include test_block.html testDivContent=site.data.testVar_file.testVar %}

Upvotes: 4

Related Questions