Braze Liquid: 5 Things You Need To Know About Liquid Conditionals (if/elsif/else)

Don’t be scared of Braze Liquid Conditionals!
Follow these 5 rules, and you’ll have a much better understanding of Braze Liquid Conditionals 🙏🏻
🗣️ WATCH FULL YOUTUBE VIDEO HERE 🗣
[Braze-mas 2023, Day 25]
What’s up everyone, my name is Allan, Founder and Consultant at For Now Marketing, and welcome to Day 25 of Braze-mas 2023, Merry Christmas!
Before we get started, if you have any questions, whether you are currently using Braze or considering using Braze, please feel free to reach out! You can find these addresses and more in the Youtube description below.
Today, we are going to talk about my favorite topic, Braze Liquid! And particularly, Liquid Conditionals, which are if/elsif/else statements.
Often times, Marketers can be intimidated when it comes to Liquid Conditionals, but if you just follow these 5 rules, you’ll have a much better understanding of Braze Liquid Conditionals.
Let’s get started!
Rule #1: EVERY {% if %} statement NEEDS a matching
{% endif %} statement
A very common syntax issue I see is when Marketers forget to close the Liquid Conditional with the endif statement.
One very helpful strategy for whenever you’re writing Liquid from scratch is if you end up writing an if statement, just add the endif statement right away.
That way, you start to build the habit that every if statement needs a matching endif statement.
Without an endif statement, Braze Liquid will think you never finished your Conditional and will think the rest of your code is part of the Liquid, or often times just not render at all.
Rule #2: {% if %} is REQUIRED for every conditional block, but
{% elsif %} and {% else %} are NOT required!
Keep it simple stupid! A Conditional block just needs an if and matching endif statements to function properly.
Elsif and else statements might be necessary to achieve your logic, but they’re not required for every Conditional block.
If you’re just starting out with learning Braze Liquid, practice writing Conditional Blocks that just have if and endif statements to become more familiar. One step at a time!
Rule #3: In conditional statements, use DOUBLE “==”
Inside your Conditional statements, whenever you want to check whether a variable’s value matches something, we use double equal signs, not a single equal sign.
For example, if holiday == “Christmas”, not age = “Christmas”.
A single variable is only used when we’re assigning variables.
Rule #4: Else statements DO NOT require a logic statement
Else is your default, fallback logic. It captures every other case besides what you listed in your if and elsif statements above. That’s also why else statements come at the very end of every Conditional block, of course, besides the endif statement.
Else statements are simple; just leave it blank because it doesn’t require a logic statement!
Rule #5: When using Conditional Statements:
Liquid will read from TOP to BOTTOM, and only the FIRST, TRUE statement between each
{% if %} and {% endif %} will render
This rule could’ve been broken up into 2 rules because there are two ideas here.
First, as with most cases in Computer Science, Braze Liquid reads from top to bottom. That means that every logic statement will be evaluated starting from your very first if statement, then moving down to the next statements, ending with your else statement.
Second, as Liquid is evaluating your logic statements from top to bottom, Liquid will only render the FIRST, TRUE statement.
So as soon as Liquid detects a logic statement that is correct, that statement will be run, and no other logic statements below will be considered.
In other words, every Conditional Block only renders 1 statement.
Thank You!
That’s it for Day 25. Thank you all for following our first Braze-mas series. Hope you learned a lot during these first 25 days of December.
If you have any questions, please share them in the comments. We’re happy to help! 🙏
If you learned something from this video, please subscribe for more awesome Braze videos in the future!
Thank you for watching, and see you next time!
allan@fornowmarketing.com
fornowmarketing.com