Skip to main content

capture

Creates a new variable with a string value.

You can create complex strings with Liquid logic and variables.


Caution

Predefined Liquid objects can be overridden by variables with the same name. To make sure that you can access all Liquid objects, make sure that your variable name doesn't match a predefined object's name.


Syntax

{% capture variable %}
value
{% endcapture %}
variable

The name of the variable being created.

value

The value you want to assign to the variable.

{%- assign up_title = product.title | upcase -%}
{%- assign down_title = product.title | downcase -%}
{%- assign show_up_title = true -%}

{%- capture title -%}
{% if show_up_title -%}
Upcase title: {{ up_title }}
{%- else -%}
Downcase title: {{ down_title }}
{%- endif %}
{%- endcapture %}

{{ title }}

Output

Upcase title: HEALTH POTION
Was this page helpful?