Skip to main content
Solved

How to set up my if statement correctly?

  • April 15, 2024
  • 2 replies
  • 149 views

Forum|alt.badge.img

Hello, 

Ive read the article “Use conditionals in messages” from Klaviyo and wrote an if statement trying to use the given information but when I want to send a test to myself, there is an error message saying: “There is an error in your email content.<br />The "lookup" filter requires 2 arguments, but 1 was given”

 

Here is my code, its very simple: 

{% if person|lookup:“title“ == „female“ %}

Sehr geehrte Frau {{ person|lookup:'last_name' }}

{% elif person|lookup:“title“ == „male“ %}

Sehr geehrter Herr {{ person|lookup:'last_name' }}

{% else %}

Sehr geehrte Damen und Herren,

{% endif %}

 

The Gender of our customers is set through the property “title”. So I want our female customers to be adressed as madam and the male customers as sir (Sehr geehrte Frau is German for dear madam).

 

An other example of code that is similar, but works, is this: 

{{ person|lookup:'Salutation' }} {{ person|lookup:'title' }} {{ person|lookup:'last_name' }}

So if I use person|lookup:'title' it works. But when im using it inside an if statement, it doesn't… 


What am I doing wrong? 

 

Best regards!

Best answer by KeviSunshine

Hi @Lionrip,

I think the issue is with the style of quotes you’re using. 

 

Can you try this code?

{% if person.title == "female" %}Sehr geehrte Frau {{ person.last_name }},{% elif person.title == "male" %}Sehr geehrter Herr {{ person.last_name }},{% else %}Sehr geehrte Damen und Herren,{% endif %}

 

Also, you don’t need to use the lookup “filter” for an operation like this. It doesn’t hurt, but you can use person.title or person.last_name directly for profile properties. I find it a little easier to read and write conditionals like this.

Cheers,

Kevin.

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

2 replies

KeviSunshine
Expert Problem Solver III
Forum|alt.badge.img+8
  • Expert Problem Solver III
  • 158 replies
  • Answer
  • April 15, 2024

Hi @Lionrip,

I think the issue is with the style of quotes you’re using. 

 

Can you try this code?

{% if person.title == "female" %}Sehr geehrte Frau {{ person.last_name }},{% elif person.title == "male" %}Sehr geehrter Herr {{ person.last_name }},{% else %}Sehr geehrte Damen und Herren,{% endif %}

 

Also, you don’t need to use the lookup “filter” for an operation like this. It doesn’t hurt, but you can use person.title or person.last_name directly for profile properties. I find it a little easier to read and write conditionals like this.

Cheers,

Kevin.


Forum|alt.badge.img
  • Author
  • Contributor I
  • 1 reply
  • April 16, 2024
KeviSunshine wrote:

Hi @Lionrip,

I think the issue is with the style of quotes you’re using. 

 

Can you try this code?

{% if person.title == "female" %}Sehr geehrte Frau {{ person.last_name }},{% elif person.title == "male" %}Sehr geehrter Herr {{ person.last_name }},{% else %}Sehr geehrte Damen und Herren,{% endif %}

 

Also, you don’t need to use the lookup “filter” for an operation like this. It doesn’t hurt, but you can use person.title or person.last_name directly for profile properties. I find it a little easier to read and write conditionals like this.

Cheers,

Kevin.

Hi Kevin, 

thank you very much! That fixed it :) 

best regards, 

Lion