Solved

Targeting blank values for conditional statements / IF ELSE content blocks

  • 14 January 2021
  • 4 replies
  • 72 views

Badge

Hi all,

 

Ok so originally I started writing this because i was struggling to hide / show content based on blank values but I found the article i needed and i’ve figured it out ... :sweat_smile: .

 

I’ll still post because it might be useful for someone but there’s also an extra question at the end that would be good to know for future reference!

---

I’ve been trying to get a text block to hide / show based on blank or no value i.e First_name has no value so display X instead.

 

Example below is what i’m trying to do ;

 

 

I saw this example on an article which makes sense for use in a text block but i’m struggling to write valid syntax / target the value or no value i need which is firstname:

 

{% if person|lookup:'Interested in Dogs?' and not person|lookup:'Interested in Cats?' %}
    Like dogs? Check out some great toys for your canine. 
{% elif person|lookup:'Interested in Cats?' and not person|lookup:'Interested in Dogs?' %}
    Like cats? Check out some great toys for your feline. 
{% else %} 
    Check out some great toys for your pet! 
{% endif %}

 

Also saw the following for conditional blocks which is what i’m using currently to achieve what I need;

 

First block (non personalised) is;

not person.first_name

 

Second block (personalisation);

person.first_name

 

But!... it would be good to know how to write this as an if / else statement for use in a conditional content block (for example - everything contained within one text block), was assuming it would be along the lines of;

 

{% if person|'first_name' = ''  %}

If firstname blank content

{% else %}

Show personalisation content

{% endif %}

 

Could i get a hand with getting the syntax above to work?

 

Thanks!

 

Jason

icon

Best answer by retention 15 January 2021, 09:42

@jasondstainton Glad to see that people are utilizing the if/else statements to create powerful personalization. I’ll try to answer both questions. Let’s jump to it.

When it comes to hiding entire blocks I recommend using the question mark symbol (?) option.
 

 

In this case (person.first_name), if the person has First Name the block will appear, and if he doesn’t have a First Name the block will be hidden.

On the other hand, if you just want to show/hide certain paragraph or word from a text block, you can use the if/else statements inline to achieve that. Let’s create an example.

You are a pet store and you want to say:

We care about animals very much.
And we know that you love your _____ (dog, cat, pet)!
That’s why we’ve created this super cool toy……

 

If you have the pet type property for your subscribers stored as “Pet Type = Dog/Cat”, this is how you can use the if/else statements to personalize the email.

We care about animals very much.
And we know that you love your
{% if "Dog" in person|lookup:"Pet Type" and not "Cat" in person|lookup:"Pet Type" %} dog.
{% elif "Cat" in person|lookup:"Pet Type" and not "Dog" in person|lookup:"Pet Type"  %} cat.
{% else %} pet. {% endif %}
That’s why we’ve created this super cool toy……


The results will be:
- If subscriber owns a dog, but not a cat: It will show “dog.”
- If subscriber owns a cat, but not a dog: It will show “cat.”
- If subscriber owns both dog and cat: It will show “pet.”
- If subscriber owns neither dog nor cat: It will show “pet.”

You can play around with the logic and use it to conditinally show or hide certain words or entire paragraphs.
 

Now for your specific question about the First Name, if you don’t want to use the “default” fallback option you can use the if/else statement to hide that entire section:

{% if person.first_name %}{{ first_name }}, {% endif %}Happy New Year!

If the subscriber has First Name it will show:

John, Happy New Year!


If the subscriber doesn’t have First Name it will show:

Happy New Year!


You can apply this same logic in the Subject Line and it should work fine.

You can also check our tutorial on How to Set Show/Hide Blocks Based on a Custom Profile Property, where we go over the basic settings and conditional options.

Hope this helps!

View original

4 replies

Badge

Just to bolt on to the above, since its similar topic. 

 

Can we use conditional statements statements in a subject line?

 

For example add conditional statement into the subject line box -

 

IF Firstname has a value show;

{{ first_name|default:'' }} , items in your basket are selling fast!

ELSE no value show;

Items in your basket are selling fast!

--

Just so the correct formatting can be shown for the different versions when I don’t want to use a fallback or default.

 

Thanks!

 

Userlevel 6
Badge +4

@jasondstainton Glad to see that people are utilizing the if/else statements to create powerful personalization. I’ll try to answer both questions. Let’s jump to it.

When it comes to hiding entire blocks I recommend using the question mark symbol (?) option.
 

 

In this case (person.first_name), if the person has First Name the block will appear, and if he doesn’t have a First Name the block will be hidden.

On the other hand, if you just want to show/hide certain paragraph or word from a text block, you can use the if/else statements inline to achieve that. Let’s create an example.

You are a pet store and you want to say:

We care about animals very much.
And we know that you love your _____ (dog, cat, pet)!
That’s why we’ve created this super cool toy……

 

If you have the pet type property for your subscribers stored as “Pet Type = Dog/Cat”, this is how you can use the if/else statements to personalize the email.

We care about animals very much.
And we know that you love your
{% if "Dog" in person|lookup:"Pet Type" and not "Cat" in person|lookup:"Pet Type" %} dog.
{% elif "Cat" in person|lookup:"Pet Type" and not "Dog" in person|lookup:"Pet Type"  %} cat.
{% else %} pet. {% endif %}
That’s why we’ve created this super cool toy……


The results will be:
- If subscriber owns a dog, but not a cat: It will show “dog.”
- If subscriber owns a cat, but not a dog: It will show “cat.”
- If subscriber owns both dog and cat: It will show “pet.”
- If subscriber owns neither dog nor cat: It will show “pet.”

You can play around with the logic and use it to conditinally show or hide certain words or entire paragraphs.
 

Now for your specific question about the First Name, if you don’t want to use the “default” fallback option you can use the if/else statement to hide that entire section:

{% if person.first_name %}{{ first_name }}, {% endif %}Happy New Year!

If the subscriber has First Name it will show:

John, Happy New Year!


If the subscriber doesn’t have First Name it will show:

Happy New Year!


You can apply this same logic in the Subject Line and it should work fine.

You can also check our tutorial on How to Set Show/Hide Blocks Based on a Custom Profile Property, where we go over the basic settings and conditional options.

Hope this helps!

Badge

Hi Josh,

 

Thanks for coming back on the above so quickly and for explaining on that level of detail, exactly what I needed! 

 

Many thanks

 

Jason

Badge

I have a similar related question. I have managed to setup product blocks that display Mens clothes, women or kids based on the product in browser abandonment. using “kids” in event.Categories.0 in the ?

My question Is there a way of setting up a product block that displays if the product isn’t in the men's, women’s or kids category? ideallly i want one block that goes if not in “men's or women or kids” in event.categories.0 it displays products that aren’t in these categories.

Many Thanks

Dave

Reply