Solved

Conditional Statements using contents of a property

  • 29 March 2023
  • 2 replies
  • 259 views

Badge

I’m trying to use conditional statements in a plain text email to display a different sentence depending on the contents of a profile property. 

Background: we have a product recommendation quiz, and the results populate in a customer’s profile on klaviyo. The property contains the info on three key areas, but I only need to reference part of it for this - so it’s ‘contains’ logic vs ‘is exactly’ 

In a drag+drop email I’ve successfully used the following show/hide logic to achieve a similar result when sending them the product recommendation: 

 

I’m now trying to pull the same logic through on a plain text email with if/else statements. I can get this to save, but it gives and ‘invalid template tags or filters’ error when I try to preview it: 

Hi {{ first_name }},

This is an email just for you. We hope you like it.

{% if 'Likely Starter or Weekend' in person|lookup:"TAGS-gWH3zR" %}

starter week

{% elif 'Likely Weekend or Tiny' in person|lookup:"TAGS-gWH3zR" %}

weektiny

{% elif 'Like Tiny House or Bach' in person|lookup:"TAGS-gWH3zR" %}

tinybach

{% elif 'Likely Bach or Freedom' in person|lookup:"TAGS-gWH3zR" %}

bachfree

{% elif 'Likely Freedom or Lifestyle' in person|lookup:"TAGS-gWH3zR" %}

freelife

{% else %}

Have you heard about our VIP program? Join today on our website to start earning rewards.

{% endif %}

Looking at some help articles I thought that maybe changing the “ to ‘ on the TAGS bit, but that gives this error: “There is an error in your email content. The "lookup" filter requires 2 arguments, but 1 was given”

Each of those contents also exists as its own property stored as true/false - am I better off setting it up using these tags instead? (they’re all true because this is my profile for testing)

If anyone has some insight it would be greatly appreciated!

icon

Best answer by stephen.trumble 30 March 2023, 22:01

View original

2 replies

Userlevel 7
Badge +60

Hey@Rachel G 

Welcome to the community and congrats on your first post! Thank you so much for reaching out for help with your if/else statements. 

From the image you shared of the custom properties on your profile, it looks like each of them are net new properties and therefor using the TAGS-gWH3zR property for all of your if else statements would not work. I would recommend use true/false logic for each of the profile properties shown above. as an example:

{% if person|lookup: ‘T-gWH3zR: Likely Tiny House or Bach’= ‘true’ %}

tinybach

Give that a shot and see if you have success!

Badge

Thanks @stephen.trumble! I’ve finally gotten it to show me a preview now with this:

<p>This is an email just for you. We hope you like it.</p>

{% if person|lookup:'T-gWH3zR: Likely Starter or Weekend' = 'true' %}

<p>starter week</p>

{% elif person|lookup:'T-gWH3zR: Likely Weekend or Tiny' = 'true' %}

<p>weektiny&nbsp;</p>

{% elif person|lookup:'T-gWH3zR: Like Tiny House or Bach' = 'true' %}

<p>tinybach&nbsp;</p>

{% elif person|lookup:'T-gWH3zR: Likely Bach or Freedom' = 'true' %}

<p>bachfree&nbsp;</p>

{% elif person|lookup:'T-gWH3zR: Likely Freedom or Lifestyle' = 'true' %}

<p>freelife&nbsp;</p>

{% else %}

<p>Have you heard about our VIP program? Join today on our website to start earning rewards.</p>

{% endif %}

<p>&nbsp;</p>

<p>The Team</p>

However, it doesn’t seem to be working, all previews just show the Else version. I’ve confirmed that the preview profiles have at least one of those properties as true. Any idea what might be going wrong?

Reply