Fallback for placeholders in Newsletters

5 posts by 3 authors in: Forums > CMS Builder
Last Post: March 2, 2020   (RSS)

By JeffC - February 13, 2020

Hi

Is it possible to create a fallback for instances where you do not have information in a field.

For example:

Dear #contact.name#

Would appear as:

Dear Colleague

Where contact.name is empty.

Thanks

Jeff

Jeff

By JeffC - February 15, 2020

Thanks Alan

I am hoping that there is a function to provide a fallback directly in the Newsletter.

When compiling a newsletter, to include a persons name, you would literally (no php in the newsletter itself) write: #name#

I used to use Campaign Monitor to deliver my emails. It has has a similar format for Placeholders, and had a function to provide a fallback in the placeholder itself. Placeholders in CM look like this: [firstname,fallback=Colleague]

Do you know if there is anything similar in cmsb?

Thanks

Jeff

By gregThomas - February 26, 2020

Hey Jeff,

One of the less well-known features of Newsletter Builder is the ability to customize the placeholders. You need to create a new file to your Newsletter Builder plugin directory called 'newsletterBuilder-custom-placeholders.php'. This file will be read by the plugin automatically and allows you to update any of the placeholders as you'd like. So to add a default value to the placeholder contact name you'd add the following to the file:

<?php

  if(empty($placeholders['contact.name'])) {
    $placeholders['contact.name'] = 'Colleague';
  }

You can add as many default values for the placeholders as you'd like by adding an if statement like the one above for each.

Let me know if you've got any questions.

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By JeffC - March 2, 2020

Exactly what I was after, thanks Greg

Jeff