Display fallback value for missing tag values

Jeff Spicher

New Member
Hello guys, l have a question -- is it possible to have a "default" or fallback value for custom tags if they are empty?

For example, l understand that [FNAME] pulls in the subscriber's first name, but what if that happens to be blank for a particular subscriber, is it possible to just display something like "Friend" or something instead of it just being blank?

For example it works similar to this in other email platforms:
[FNAME|Friend]
 
This might be a long shot, but I'm trying anyway:
How would I be able to create entire fallback phrases (i.e. for the subject line)?
Example:
subject (for populated [FNAME]): [FNAME], did you know that it rains in Spain?
subject (for empty [FNAME]): 3 reasons why it rains in Spain...
I know I can simply create a segment based on a filter, but keeping it all within one campaign would be so much neater.
 
Just to give an example using a complete fantasy expression, something like...
[VARIABLE_CONTENT:[FNAME], did you know that it rains in Spain?|3 reasons why it rains in Spain...]
The above is obviously non-existent. Just wanted to demonstrate what I am after.
Kind-of using the [RANDOM_CONTENT] functionality, but making it conditional.
 
@nadworks - If you want to go this path, you can try to go in backend > settings > campaigns and enable the template engine.
What this will do, is will enable twig ( https://twig.sensiolabs.org/doc/2.x/ ) which means you can do this in the subject lines:
Code:
{% if FNAME %} FNAME, did you know that it rains in Spain  {% else %} 3 reasons why it rains in Spain... {% endif %}
 
Thanks. Unfortunately, that doesn't quite work. Regardless of available FNAME or not, it always uses
3 reasons why it rains in Spain...
Any idea where the error is?

I also tried
Code:
{% if FNAME == true %} FNAME, did you know that it rains in Spain  {% else %} 3 reasons why it rains in Spain... {% endif %}
With the same result: Just the "else" part was picked up - even where I had the first name.

Then I tried
Code:
{% if FNAME == 'Nadja' %} FNAME, did you know that it rains in Spain  {% else %} 3 reasons why it rains in Spain... {% endif %}
'Nadja' is a definite value in the field. However yet again, it didn't work. Is it possible that it just doesn't work in the subject line maybe?

I've been looking for examples in the TWIG documentation. But I'm not enough of a developer to understand what and where exactly to look for my specific solution. Sorry.
 
Last edited:
@nadworks - This is what you get for doing pre-optimizations :-s My bad on this one, it was a bug i have fixed.
Please open /apps/common/components/helpers/CampaignHelper.php and look for "public static function getCommonTagsSearchReplace" and inside it, delete these lines:
PHP:
// since 1.3.9.8 - if no tag, stop
if (strpos($content, '[') === false || strpos($content, ']') === false) {
    return array();
}
Then save you file, this should then make things work as expected:
Code:
{% if FNAME %} FNAME, did you know that it rains in Spain  {% else %} 3 reasons why it rains in Spain... {% endif %}
 
Excellent, so what eventually worked was...
Code:
{% if FNAME %} [FNAME], did you know that it rains in Spain  {% else %} 3 reasons why it rains in Spain... {% endif %}

Thanks!!
 
Hi,

I tried the above method and it's working fine except a weird problem.
When I send a test email to mail tester. com then it replaces the fallback value with the name "Robin", but I'm using "Fans" as my fallback value.

Edit:- I Just clicked the unsubscribe link in the email and then re-subscribe on the same page and found a subscriber with the name "Robin" with a valid email address, so the problem is not related to the emails which are not present in a list.

It's really weird because I had sent the test email to the mail-tester's testing email address and when I clicked the unsubscribe link it unsubscribed one of my list subscribers.

Could you please tell me if it is configured to work like this or it is a bug.

Thank you!
Kind Regards
Zameer
 
Last edited:
Could you please tell me if it is configured to work like this or it is a bug.
When you do a test send, it will pick a random subscriber from your list, otherwise it wouldn't know how to replace your tags from the template, because you cannot specify all those values in the test email, so it works as expected, even if it's a bit weird, once you understand the rationale behind it, it makes sense.
 
Back
Top