4

We have an address block on some pdf templates in CiviCRM some contacts have address2 or address3 lines while other do not.

Using the normal tokens we end up getting blank lines and the address block looks messy.

Has anyone found a way of conditionally formatting the address block to not create these blank lines?

I was looking for some IF(Token not NULL THEN add Token and carriage return ELSE nothing) but can't find any solution online.

Thanks,

Dave

  • You should be able to do this by entering a curly brace with a space in it { }. Could you please update this ticket with your current address block token? – Jon G - Megaphone Tech Oct 27 '15 at 17:33
  • Not sure I follow you in terms of how you would use { }? Current block is: {contact.addressee} {contact.street_address} {contact.supplemental_address_1} {contact.supplemental_address_2} ​{contact.city} {contact.postal_code} {contact.postal_greeting} But if either supplemental address fields are blank you get a blank row. Thanks - PS - the normal carriage returns have been removed in this comment. – Dave Oct 27 '15 at 20:51
2

Try to use as below which does the job

<div>{contact.addressee}</div>
<div>{contact.street_address}</div>
<div>{contact.supplemental_address_1}</div>
<div>{contact.supplemental_address_2}</div>
<div>​{contact.city}</div>
<div>{contact.postal_code}</div>

OR

I am not sure about replacing the in-build token using IF statement

But you can create an Address block token on your own where you can remove blank lines - and you can use address block token in the PDF

http://wiki.civicrm.org/confluence/display/CRMDOC/Customized+%28and+Custom%29+Tokens

I guess this help - if you need more details please let me know - thanks

  • creating a new token requires coding and I was hoping the answer would be simpler than that! I see some references to smarty tokens and conditional things being not available in labels with the implication that they are available in pdf letters.... – Mick Kahn Oct 13 '17 at 18:53
0

Aha - worked out how to do this. You need to use smarty for conditional logic. See https://docs.civicrm.org/sysadmin/en/latest/config/message-templates/ to see how to turn on smarty for mail/pdf templates. I also used https://www.smarty.net/docs/en/language.function.capture.tpl to work out how to do it.

Then in the template you need something like:

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

But where I have XXX above there is line break HTML markup (Can't work out how to get that through the markup for stack exchange. Hope that makes sense!

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.