Display fallback value for missing tag values

Discussion in 'Tips and tricks' started by Jeff Spicher, Feb 3, 2016.

  1. Jeff Spicher

    Jeff Spicher New Member

    Joined:
    Feb 3, 2016
    Messages:
    1
    Likes Received:
    0
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    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]
     
  2. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,354
    Likes Received:
    2,406
    @Jeff Spicher - There's a filter for that, [FNAME:filter:defaultValue(Whatever)] should do the trick.
     
  3. JAMJA

    JAMJA New Member

    Joined:
    May 18, 2016
    Messages:
    19
    Likes Received:
    7
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    Last edited: Jun 5, 2016
  4. Ángel Candelaria

    Ángel Candelaria New Member

    Joined:
    Jun 8, 2016
    Messages:
    8
    Likes Received:
    4
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    Hi.
    Same here. I tested this filter but they didn't work using the format suggested:
    [FNAME:defaultValue(Whatever)]
     
  5. Ángel Candelaria

    Ángel Candelaria New Member

    Joined:
    Jun 8, 2016
    Messages:
    8
    Likes Received:
    4
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    Nevermind, I got it.
    For whomever may be useful, this is what worked for me:
    [FNAME:filter:defaultvalue(fallback text)]
     
    twisted1919 and frm.mwz like this.
  6. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,354
    Likes Received:
    2,406
    @Ángel Candelaria / @frm.mwz - Since the case sensitivity of this creates issues, from next release, defaultValue and defaultvalue will both work.
     
    frm.mwz and Ángel Candelaria like this.
  7. nadworks

    nadworks Member

    Joined:
    Apr 20, 2015
    Messages:
    106
    Likes Received:
    13
    S.E:
    2019-12-16 02:05:25
    L.T:
    Regular
    L.C:
    2
    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.
     
  8. nadworks

    nadworks Member

    Joined:
    Apr 20, 2015
    Messages:
    106
    Likes Received:
    13
    S.E:
    2019-12-16 02:05:25
    L.T:
    Regular
    L.C:
    2
    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.
     
  9. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,354
    Likes Received:
    2,406
    @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 %}
    
     
    frm.mwz likes this.
  10. nadworks

    nadworks Member

    Joined:
    Apr 20, 2015
    Messages:
    106
    Likes Received:
    13
    S.E:
    2019-12-16 02:05:25
    L.T:
    Regular
    L.C:
    2
    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: May 26, 2017
  11. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,354
    Likes Received:
    2,406
    @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 %}
    
     
  12. nadworks

    nadworks Member

    Joined:
    Apr 20, 2015
    Messages:
    106
    Likes Received:
    13
    S.E:
    2019-12-16 02:05:25
    L.T:
    Regular
    L.C:
    2
    Aaaah - star! Will try that. Thanks.
     
    twisted1919 likes this.
  13. nadworks

    nadworks Member

    Joined:
    Apr 20, 2015
    Messages:
    106
    Likes Received:
    13
    S.E:
    2019-12-16 02:05:25
    L.T:
    Regular
    L.C:
    2
    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!!
     
    twisted1919 likes this.
  14. Nick Thacke

    Nick Thacke New Member

    Joined:
    Aug 29, 2019
    Messages:
    24
    Likes Received:
    4
    S.E:
    2020-02-27 13:39:18
    L.T:
    Regular
    L.C:
    1
    I just tried this and it didn’t parse... to be clear, did you actually include the word “filter” in the string?
     
  15. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,354
    Likes Received:
    2,406
    @Nick Thacke - Yes, that's correct, you need the word filter, so:
    [FNAME:filter:defaultValue(AAAAAA)]
     
  16. Zameer K

    Zameer K New Member

    Joined:
    Jul 20, 2019
    Messages:
    1
    Likes Received:
    0
    S.E:
    2020-01-16 11:12:09
    L.T:
    Regular
    L.C:
    1
    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: Oct 4, 2019

Share This Page