Skip to main content
Solved

Dynamic content using custom properties and conditional language

  • December 20, 2024
  • 6 replies
  • 39 views

Forum|alt.badge.img+3

I want to write a section of my email to display a sentence based on the value of a custom property.

Here’s an example:

The value of Grown Tomatoes Before? is: 

{% if person|lookup:'Grown Tomatoes Before?' == 'Yes' %}

Yes, they have.

{% elsif person|lookup:'Grown Tomatoes Before?' == 'No' %}

No, they have not.

{% else %}

Unknown value.

{% endif %

 

But, this doesn’t seem to work.

Best answer by MANSIR2094

To dynamically display content based on a custom property in your email, the correct syntax in Klaviyo is:

 

liquid

Copy code

{% if person|lookup:'Grown Tomatoes Before?' == 'Yes' %} Yes, they have. {% elsif person|lookup:'Grown Tomatoes Before?' == 'No' %} No, they have not. {% else %} Unknown value. {% endif %}

If this still doesn’t work, there might be an issue with how the property is stored or retrieved. Double-check:

  1. The property name matches exactly, including capitalization.
  2. The property exists in the profile you're testing.

For further help or implementation guidance, feel free to reach out to me on WhatsApp at [+234 9151237531]. I’ll help you troubleshoot and get it working!

View original
Did this topic or the replies in the thread help you find an answer to your question?

6 replies

MANSIR2094
Problem Solver IV
Forum|alt.badge.img+13
  • Problem Solver IV
  • 188 replies
  • December 20, 2024

Hi RedPhive

It seems like you're encountering an issue with your email template logic. I'd be happy to help you troubleshoot this! Please reach out to me directly on WhatsApp at [+234 9151237531], and we can work through this together.

Looking forward to assisting you!


Mich expert
Problem Solver IV
Forum|alt.badge.img+11
  • Problem Solver IV
  • 64 replies
  • December 21, 2024

It looks like you're on the right track with using Liquid syntax for your email, but there’s a small syntax error in your code. The closing tag for the endif statement should be {% endif %} instead of {% endif %. Here’s the corrected version:

 

liquid

Copy

The value of Grown Tomatoes Before? is: {% if person|lookup:'Grown Tomatoes Before?' == 'Yes' %} Yes, they have. {% elsif person|lookup:'Grown Tomatoes Before?' == 'No' %} No, they have not. {% else %} Unknown value. {% endif %}

Explanation:

  • Correct Syntax: Make sure to use {% endif %} to properly close your conditional statement.
  • Lookup Function: Ensure that the custom property name is spelled correctly and matches exactly what is in your database.

Additional Tips:

  • Testing: Always test your email with sample data to ensure that the conditions are working as expected.
  • Debugging: If it still doesn’t work, check if the custom property is set correctly in your database for the contacts you are testing.

Feel free to reach out if you need further assistance!

Best Regard

Mic pro


Forum|alt.badge.img+3
  • Author
  • Problem Solver I
  • 8 replies
  • December 21, 2024

That missing curly bracket was a typo.

The code still doesn’t work correctly.


Mich expert
Problem Solver IV
Forum|alt.badge.img+11
  • Problem Solver IV
  • 64 replies
  • December 21, 2024

It looks like you're dealing with a Liquid syntax issue in your email code. You're absolutely correct that the closing statement should be `{% endif %}` rather than `{% endif %}`. The updated version of your Liquid code will look like this:

```liquid
The value of Grown Tomatoes Before? is: 
{% if person|lookup:'Grown Tomatoes Before?' == 'Yes' %}
  Yes, they have.
{% elsif person|lookup:'Grown Tomatoes Before?' == 'No' %}
  No, they have not.
{% else %}
  Unknown value.
{% endif %}
```

### Key points:
- **Correct closing tag**: `{% endif %}` is required to properly close the `if` block.
- **Proper property name**: Double-check that `'Grown Tomatoes Before?'` matches the field name in your database, paying attention to spaces and capitalization.
- **Lookup Function**: Using `person|lookup` retrieves the value from the contact's database.

### Additional Tips:
1. **Test with sample data**: Ensure that the custom property exists for the contact records you're testing with. If it's missing or incorrectly formatted, it might cause unexpected results.
2. **Debugging**: If you're still facing issues, check for any typos or misconfigurations in your CRM or database, as this can cause the conditional logic to fail.

Let me know if you run into any other problems, and I'll be happy to help! you can always reach out to me on +2348087340172

Best regard 

Mic pro


Amos Peace
Problem Solver III
Forum|alt.badge.img+5
  • Problem Solver III
  • 57 replies
  • December 21, 2024

Hello RedPhive,

It seems like you're trying to display different text based on the value of a custom property in your email. The issue might be with the syntax. Here’s a more streamlined approach:

 

liquid

Copy code

{% if person.Grown_Tomatoes_Before == 'Yes' %} Yes, they have. {% elsif person.Grown_Tomatoes_Before == 'No' %} No, they have not. {% else %} Unknown value. {% endif %}

Ensure the property name is exactly as defined in your system, and check for any syntax issues with your variables.

If you still need help or have other questions, feel free to reach out to me on WhatsApp at [+234 9023453575]. I'd be happy to assist!


MANSIR2094
Problem Solver IV
Forum|alt.badge.img+13
  • Problem Solver IV
  • 188 replies
  • Answer
  • December 21, 2024

To dynamically display content based on a custom property in your email, the correct syntax in Klaviyo is:

 

liquid

Copy code

{% if person|lookup:'Grown Tomatoes Before?' == 'Yes' %} Yes, they have. {% elsif person|lookup:'Grown Tomatoes Before?' == 'No' %} No, they have not. {% else %} Unknown value. {% endif %}

If this still doesn’t work, there might be an issue with how the property is stored or retrieved. Double-check:

  1. The property name matches exactly, including capitalization.
  2. The property exists in the profile you're testing.

For further help or implementation guidance, feel free to reach out to me on WhatsApp at [+234 9151237531]. I’ll help you troubleshoot and get it working!