Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 857
biw Avatar asked Jun 03 '15 22:06

biw


People also ask

What does capture do in liquid?

Capture allows you to write complex logic and strings and then capture the output of a block of liquid to a variable. This means you can write functions for your liquid in one place and then use the variable in much simplified liquid.

What is liquid Jekyll?

What is Liquid? Liquid is a templating language used in Jekyll to process your site's pages. In other words, it helps you make your HTML pages a bit more dynamic, for example adding logic or using content from elsewhere. This doesn't require any setup - we can just start using it.

What is front matter in Jekyll?

Front matter is a snippet of YAML placed between two triple-dashed lines at the start of a file. You can use front matter to set variables for the page: --- my_number: 5 --- You can call front matter variables in Liquid using the page variable.


1 Answers

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

like image 200
Zach Dennis Avatar answered Oct 12 '22 02:10

Zach Dennis