1

How do I do this in a Smarty template:

If {contact.supplemental_address_1} is not empty then

{contact.supplemental_address_1}

2
{capture assign=temp}{contact.supplemental_address_1}{/capture} {if $temp ne ""} {$temp}
{/if} 

is what I do. I got the idea from the source referenced above. You also need to ensure that smarty is turned on in civicrm.settings.php

1

Found a whole bunch of examples - including an isset one in Example 7.15

https://www.smarty.net/docsv2/en/language.function.if.tpl

1

A little cleaner approach

{if $contact.supplemental_address_1}{contact.supplemental_address_1}{/if}
  • Are you sure about this? It doesn't work for me. Fine if the field is null, but it doesn't print if it is none null. I'm on CiviCRM 4.7.24 and WordPress 4.9 The documentation suggests my solution below. – Mick Kahn Nov 23 '17 at 1:08
  • Yes. This works in Civi 4.7.20 + WordPress 4.8 and also Civi 4.6.10 + Drupal 7.41 (with smarty turned on of course). I also tested with a few other contact variables include the first_name token listed in the example. They all worked when I used the $variable in the if statement. I hadn't taken an in-depth look at the user guide, I've used the shorter if logic based on samples in the default contribution receipt text. I can't speak to why the user guide recommends assigning an existing contact token first, that's above my pay grade ;) – RayWright Nov 23 '17 at 1:38
  • Will try again! – Mick Kahn Nov 23 '17 at 8:57
  • Tried again very carefully and it still doesn't work. But as I have my own less elegant solution I'm not going to spend more time on it. – Mick Kahn Nov 23 '17 at 13:43
  • Looks nice but didn't quite work – Yossi Dec 3 '17 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.