LIQUID FOR TECHNICAL MARKETERS: Assign & Capture
Assign and Capture tags are the two ways to create variables in Liquid.
If you’re an active Liquid user or have been following our videos, Assign tags will soon become second nature. Assign tags are necessary in almost every Liquid use case.
But when do we use the Capture tag? Watch this video to find out!
🗣️ WATCH FULL YOUTUBE VIDEO HERE 🗣
What’s up everyone, my name is Allan, Founder and Consultant at For Now Marketing, and welcome to LIQUID FOR TECHNICAL MARKETERS!
If your goal is to improve your Liquid coding skills, then please:
- like this video
- subscribe to our channel
- watch this video all the way to the end
- and keep an eye out for more videos in the future.
Today, we’re going to talk about the Assign and Capture tags which are used to create variables in Liquid.
Let’s get started.
Assign Tag
The Assign tag will be used in almost every Liquid use case, since it’s the main Liquid tag that allows us to create variables.
We’ve already seen examples of the Assign Tag, even before we talked about what tags were because the Assign Tag is that crucial and fundamental to Liquid.
The syntax is simple: open up the Assign Tag with the curly bracket percent symbol, type the word assign in lowercase, and type in the variable name.
One thing to note is that variable names can only be one word. That’s why we often see these two types of variable naming conventions.
The first naming convention is called camelCase, and it’s called camelCase because the capitalized C looks like a camel hump. So if we were to create a variable for a user’s first name, that could look like this:
{% assign firstName = “Allan” %}
The second, and the more common naming convention is called lower_with_under. And the variable is literally written in lower case and with underscores. The same example for first name would look like this in lower_with_under format:
{% assign first_name = “Allan” %}
Why Assign?
Now, it’s possible to render values directly in Liquid, without assigning them to variables. For example, if I simply wrote , this would render “allan”, and I can even apply filters to this value directly, like {{ “allan” | capitalize }}.
However, if we had to insert the first name multiple times throughout a message, it would be cumbersome to have to write out the value every single time the first name was mentioned, especially if we’re having to add filters.
By assigning a variable with a specific value, that variable and its value can be referenced over and over again throughout our message, allowing us to be flexible in our Liquid coding.
When to Capture?
Lastly, let’s talk about when to use the Capture Tag instead of the Assign Tag.
First, the Capture Tag works by “capturing” everything that’s between the capture and endcapture tags, and assigning the entire value to the variable.
Here’s an example:
{% assign city = "Los Angeles" %}
{% assign favorite_software = "Braze" %}
{% capture about_me %}
I live in {{ city }} and my favorite Marketing software is {{ favorite_software }}.
{% endcapture %}
{{ about_me }}
In this example, the variable “about_me” will render the entire sentence starting with “I live in” and ending with the variable “favorite_software”.
Therefore, the Capture Tag is especially helpful if our variable values are multi-line values, AND/OR relies on other variable values.
The Capture Tag simply captures the entire portion between the capture and endcapture tags, making it easy to create variables with a value that consists of an entire sentence using two other variables.
Thank You!
That’s it for today! Even though the Assign Tag will be our best friend most of the times, there will definitely be use cases where the Capture Tag is necessary. So please keep an eye out for those situations, and let us know if/when you end up using the Capture Tag successfully!
Thank you for watching, and see you next time!
fornowmarketing.com
Hello, World!