Forum Discussion

mylinhp's avatar
mylinhp
Active Member II
2 years ago

Liquid logic - using a conditional within forloop

Hi all! I'm running into an issue where my liquid logic is breaking my email... not sure if i'm doing something wrong or if what i'm trying to do isn't possible...

I'm trying to use a conditional within a forloop using canvas entry properties... i've followed the template below but the email won't even send when i test it: 

{% for item in {{canvas_entry_properties.${array}}} %}
{% if {{item.metric}} > 1 %}
{{item.image}}
{% endif %}
{% endfor %}

i know the conditional is breaking it because the email sends successfully when i remove it. anybody know what's going on here?

  • It looks like it should work.

    I'd be very interested to see if the item.metric value is always present and of the type you're expecting it to be.

    I also have some vague memory of some operators (maybe '>', not sure) being very sensitive to whitespace around them. Do make sure you have all the spaces in your actual liquid as you do here.

  • bob's avatar
    bob
    Specialist

    It looks like it should work.

    I'd be very interested to see if the item.metric value is always present and of the type you're expecting it to be.

    I also have some vague memory of some operators (maybe '>', not sure) being very sensitive to whitespace around them. Do make sure you have all the spaces in your actual liquid as you do here.

    • mylinhp's avatar
      mylinhp
      Active Member II

      hi bob, thanks so much! that was a good callout - solution was to treat it as a string instead of a number. that solved it.

  • DavidO's avatar
    DavidO
    Strategist II

    Hi mylinhp 

    Just to confirm, when you note you've removed the conditional, does it still render {{item.image}} successfully. 
    For example:

     

    {% for item in {{canvas_entry_properties.${array}}} %}
    {{item.image}}
    {% endfor %}

     

     

    • mylinhp's avatar
      mylinhp
      Active Member II

      Hi David! yes, correct. {{item.image}} successfully shows when i remove the conditional.

  • Max's avatar
    Max
    Specialist

    Hey mylinhp,

    can you give some details about the array? Do you have an array of objects in your event properties? What exact you want to achieve?

    This would help to give you a better answer to your problem 🙂 .

     

    • mylinhp's avatar
      mylinhp
      Active Member II

      Hi Max! thanks for checking in. i was able to find a solution from bob's reply above. solution was to treat it as a string instead of a number. thanks!