Assign / Capture

You are here:

Assign and Capture Tags

As you become more familiar with Lava you'll find it necessary to start creating your own variables for use in your templates. This guide will walk you through several options you have in creating and using variables within Lava.

Starting Simple

The simplest way to create a variable is with the assign tag. Its usage is pretty straight forward.

{% assign name = 'Ted Decker' %}
Oh it's you {{ name }}...

Going Deeper

A more realistic sample of using variables might be one that uses them with filters and conditional logic.

{% assign hour = 'Now' | Date:' H' %}

{% if hour <= 12 %}
    Good Morning!
{% elseif hour < 6 %}
    Good Afternoon!
{% else %}    
    Good Evening!
{% endif %}

Complex Assignments

If you would like to combine several strings into a single variable you can use the capture tag. This tag 'captures' whatever is rendered inside it and stores it into a variable instead of displaying it on the screen.

{% capture message %}{{ Person.NickName }} is a {{ Person.ConnectionStatusValue.Value }}{% endcapture %}
{{ message }}