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 AlanAlonso - February 14, 2020

Try this

<?php // if record show this
 if ($record['record']): ?>
<?php echo htmlencode($record['record']) ?>

<?php // if no record show this
 else: ?>
<?php echo "Colleague"; ?>
<?php endif ?>

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