Forum Discussion
Loop through a catalog to display the product a user has as a custom attribute
Hello,
So I am trying to display some Liquid logic into an email template. The idea is that I have a catalog named house_properties with fields: id, name and description.
Each user has a custom attribute called user_product_id which we should use in the Liquid code to display the name of the product from the catalog if the two id's are the same.
This is the Liquid code I have been using, but apparently is not working. Can someone please let me know what am I missing here?
{% assign user_product_id = {{ custom_attribute.${user_product_id} }} %}
<!-- Loop through each row in the catalog -->
{% for row in house_properties %}
<!-- Loop through each item in the current row -->
{% for item in row %}
<!-- Check if the item name contains the user's custom attribute -->
{% if item.id == {{ custom_attribute.${user_product_id} }} %}
{{ item.name }}
{% endif %}
{% endfor %}
{% endfor %}
Thank you in advance!
Elena
- DavidOStrategist II
Hi elena14
I'm assuming the house properties catalog is assigned early on so the loop knows which catalog to loop through.
Otherwise this looks pretty good to me except I can't see where you are using the assigned user_prodcut_id? Should it be part of your IF statement rather than the custom attribute liquid so the code would look like this:{% assign user_product_id = {{ custom_attribute.${user_product_id} }} %} <!-- Loop through each row in the catalog --> {% for row in house_properties %} <!-- Loop through each item in the current row --> {% for item in row %} <!-- Check if the item name contains the user's custom attribute --> {% if item.id == user_product_id %} {{ item.name }} {% endif %} {% endfor %} {% endfor %}
- elena14Practitioner
Hi DavidO ,
Actually I am not sure which is the correct way to assign the correct catalog, so we know which catalog we are looping through.
According to Braze documentation this is the code:
{% catalog_items house_properties %}
But this is not working with the full code above. Can you please advice how we can actually loop through the catalog items? Thanks!
Related Content
- 3 months ago
- 10 months ago
- 8 months ago
- 6 months ago