Tags
set
Assign a value or captured markup to a variable.
set assigns a value to a variable.
page.kiln
{% set title = page.title ?? "Untitled" %}
<h1>{{ title }}</h1>
Output
<h1>Untitled</h1>
Capturing markup
The block form renders its content and stores the result. Use it to build a piece of markup once and output it in several places.
page.kiln
{% set logo %}<a href="/" class="logo">{{ site.name }}</a>{% endset %}
<header>{{ logo }}</header>
<footer>{{ logo }}</footer>
Output
<header><a href="/" class="logo">Acme</a></header>
<footer><a href="/" class="logo">Acme</a></footer>
The captured markup is already escaped, so it isn't escaped again when you output it.
Where variables live
set updates a variable in the scope where it already exists, or creates it in the current scope. See Variables and scope.
In a page that extends a layout, top-level set tags run before the layout renders, so the layout and every block can use them.