Forum Discussion
Custom Block with attributes
Hello,
Does anyone know if it's possible to display a content block only to certain customers who have a specific custom attribute? How would you do that?
Than you 🙂
Hello louizec03 👋
You can do this using Liquid language which is built into Braze. There are great docs on it here:
Liquid (braze.com)
or I have a crash Liquid 101 crash course on YouTube
A Beginner's Guide to Braze Liquid: Mastering the BasicsFor your specific use case you could write something similar to the below but replace the custom attributes and content blocks with your own:
{% if {{custom_attribute.${exports}}} == 'movie' %} {{content_blocks.${movie_block}}} {% else %} {{content_blocks.${generic_block}}} {% endif %}
In this example the 'if' statement tells braze to check if the custom attribute 'exports' contains the string 'movie', and if it does, the 'if' statement equals true, and it will send the user the 'movie_block' content block. If the custom attribute does not contain 'movie' then the 'if' statement is false and the 'else' statement becomes true and the 'generic_block' will be sent instead. Else, essentially becomes the fallback if the former is not true.
You can expand this out to check multiple things using 'elsif':
{% if {{custom_attribute.${exports}}} == 'movie' %} {{content_blocks.${movie_block}}} {% elsif {{custom_attribute.${exports}}} == 'video' %} {{content_blocks.${video_block}}} {% else %} {{content_blocks.${generic_block}}} {% endif %}
Everything is the same as before in this example except an 'elsif' is added which checks if the custom attribute 'exports' equals 'video', in which case it would become true and send the 'video_block'. The if statement works from top to bottom:
- Is exports == movie true? Send movie_block
- If false, is exports == video true? Send video_block
- If both are false, send generic_block
You can write this liquid right inside your message and although it appears in Braze, it shouldn't appear when you test the message unless there is a typo in the code. Be sure to always open and close all brackets and don't forget the 'endif' statement or it won't work.
Happy discuss this more if you need.
David 🙂
- DavidOStrategist II
Hello louizec03 👋
You can do this using Liquid language which is built into Braze. There are great docs on it here:
Liquid (braze.com)
or I have a crash Liquid 101 crash course on YouTube
A Beginner's Guide to Braze Liquid: Mastering the BasicsFor your specific use case you could write something similar to the below but replace the custom attributes and content blocks with your own:
{% if {{custom_attribute.${exports}}} == 'movie' %} {{content_blocks.${movie_block}}} {% else %} {{content_blocks.${generic_block}}} {% endif %}
In this example the 'if' statement tells braze to check if the custom attribute 'exports' contains the string 'movie', and if it does, the 'if' statement equals true, and it will send the user the 'movie_block' content block. If the custom attribute does not contain 'movie' then the 'if' statement is false and the 'else' statement becomes true and the 'generic_block' will be sent instead. Else, essentially becomes the fallback if the former is not true.
You can expand this out to check multiple things using 'elsif':
{% if {{custom_attribute.${exports}}} == 'movie' %} {{content_blocks.${movie_block}}} {% elsif {{custom_attribute.${exports}}} == 'video' %} {{content_blocks.${video_block}}} {% else %} {{content_blocks.${generic_block}}} {% endif %}
Everything is the same as before in this example except an 'elsif' is added which checks if the custom attribute 'exports' equals 'video', in which case it would become true and send the 'video_block'. The if statement works from top to bottom:
- Is exports == movie true? Send movie_block
- If false, is exports == video true? Send video_block
- If both are false, send generic_block
You can write this liquid right inside your message and although it appears in Braze, it shouldn't appear when you test the message unless there is a typo in the code. Be sure to always open and close all brackets and don't forget the 'endif' statement or it won't work.
Happy discuss this more if you need.
David 🙂
Related Content
- 10 months ago
- 2 years ago
- 7 months ago
- 8 months ago