Solved

How to set up my if statement correctly?

  • 15 April 2024
  • 2 replies
  • 23 views

Badge

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!

icon

Best answer by KeviSunshine 15 April 2024, 17:27

View original

2 replies

Userlevel 4
Badge +7

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.

Badge

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

Reply