biw
biw

Reputation: 3085

What does {% capture var %} do in jekyll?

What does {% capture var %} do in Jekyll?

Can I for example, in a .md file do:

{% capture head %}
I am the head
{% endcapture %}

and then in the .html file do:

{{head}}

Am I using capture correctly?

Upvotes: 20

Views: 9830

Answers (1)

Zach Dennis
Zach Dennis

Reputation: 1784

capture lets you assign text to a variable name. Later on when referencing that variable you can output that text.

In your above example head is the variable name. So you're saying, place all of the text between the opening and closing capture tags in a variable named head.

Then later in {{head}} you're saying you'd like to dump the contents of that variable onto the page. There is nothing special about the name head and you could rename it to something else entirely.

You can find more information about capture on this Liquid for Designers page

Upvotes: 23

Related Questions