{% capture %}

Captures the string inside of the opening and closing tags and assigns it to a variable. Capture makes it easy to create complex strings using a variety of methods.

Syntax

{% capture [var|set|assign] name %}code block{% endcapture %}

If you do not specify one of "var", "set", or "assign", then the "var" behavior will be used - which is to save the result on the current scope.

The capture tag creates a new child scope.

If name starts with '&', will attempt to assign the value by reference.

Examples

{% capture page_description -%}
    {{ page.browser_title }} | {{ site.name }}:
    {% unless page.browser_title contains entity.title %}
        [{{ entity.title }}]
    {% endunless %}
    {{ page.meta_description | truncate: 50 '...' }}
{%- endcapture %}
The page description is "{{ page_description | escape }}"
{% capture blockContent %}
    <div class="block-outer">
        <h3 class="block-title">
            {% if article.default_page_url.is_valid %}
                <a href="{{article.default_page_url.value}}">{{article.title}}</a>
            {% else %}
                {{article.title}}
            {% endif %}
        </h3>
        <div class="block-description">{{article.summary_html}}</div>
        <div class="block-footer">Posted {{article.post_date}}</div>
    </div>
{% endcapture %}
{% include "_block_outer" content:blockContent %}

Developer Overview

Liquid Markup