CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • [Solved] Smarty logic working in emails but not PDFs
Pages: [1]

Author Topic: [Solved] Smarty logic working in emails but not PDFs  (Read 26209 times)

krypto

  • I post occasionally
  • **
  • Posts: 69
  • Karma: 5
  • IT guy for @bhahumanists. Running Civi on WP.
    • British Humanist Association
  • CiviCRM version: 4.5.8
  • CMS version: WordPress 4.x
  • MySQL version: 5.5.x
  • PHP version: 5.5.x
[Solved] Smarty logic working in emails but not PDFs
July 25, 2013, 10:30:11 am
We're using smarty logic in our templates, and there's a weird inconsistency between emails and PDFs. We use the following to show someone's address, if they have one:

{if !empty($contact.street_address)}{contact.street_address}{/if}

This works fine in emails, but not in 'Print PDF Letter'. The street_address just doesn't appear. It does if you take it out of the if statement, though.

Is this meant to happen? We're due to upgrade to 4.3 soon, so I can wait until then to see if it's fixed (hard to test in the demo site as you need the smarty template setting in the config php). But I just wanted to check I wasn't missing something...
« Last Edit: July 29, 2013, 08:13:55 am by krypto »

krypto

  • I post occasionally
  • **
  • Posts: 69
  • Karma: 5
  • IT guy for @bhahumanists. Running Civi on WP.
    • British Humanist Association
  • CiviCRM version: 4.5.8
  • CMS version: WordPress 4.x
  • MySQL version: 5.5.x
  • PHP version: 5.5.x
Re: Smarty logic working in emails but not PDFs
July 29, 2013, 08:13:39 am
Sorted this one using the tips in: http://forum.civicrm.org/index.php?topic=28749.0. In short: edited CRM/Contact/Form/Task/PDFLetterCommon.php from:

$smarty->assign_by_ref('contact', $contact);

to

$smarty->assign_by_ref('contact', $contact[$contactId]);

As the original author says, it'd be good to know if this is breaking something else...
« Last Edit: July 29, 2013, 08:17:03 am by krypto »

gibsonoliver

  • I post occasionally
  • **
  • Posts: 65
  • Karma: 2
    • Northbridge Digital
Re: [Solved] Smarty logic working in emails but not PDFs
December 08, 2014, 06:10:02 am
There aren't many posts on the forum re smarty address logic and PDF letters so we thought this may be of use.

The code below details how you assign the smarty variables then how we applied some logic to the address layout.

Firstly capture all the address elements so smarty can read them

{capture assign=individual_prefix}{contact.individual_prefix}{/capture}
{capture assign=first_name}{contact.first_name}{/capture}
{capture assign=last_name}{contact.last_name}{/capture}
{capture assign=street_address}{contact.street_address}{/capture}
{capture assign=supplemental_address_1}{contact.supplemental_address_1}{/capture}
{capture assign=supplemental_address_2}{contact.supplemental_address_2}{/capture}
{capture assign=city}{contact.city}{/capture}
{capture assign=postal_code}{contact.postal_code}{/capture}

Then create 3 commas that we can use in the logic

{capture assign=comma1}{', '}{/capture}
{capture assign=comma2}{', '}{/capture}
{capture assign=comma3}{', '}{/capture}

Then use some if statements that check if a field is empty.
If the field is empty set the comma value to empty so it won't appear in the PDF letter.

{if $street_address eq ''}
   {assign var="comma1" value=""}
{/if}
{if $supplemental_address_2 eq ''}
   {assign var="comma2" value=""}
{/if}
{if $city eq ''}
   {assign var="comma3" value=""}
{/if}

Then create the address over 3 lines with logic commas on the second and third line.
So comma 1 will disappear  if there is no street address.
Comma 2 will disappear  if there is no supplemental address 2.
Comma 3 will disappear  if there is no city.

<p>{$individual_prefix} {$first_name} {$last_name}<br />
{$street_address}{$comma1}{$supplemental_address_1}<br />
{$supplemental_address_2}{$comma2}{$city}{$comma3}{$postal_code}</p>

Oliver
Oliver Gibson, Northbridge Digital

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • [Solved] Smarty logic working in emails but not PDFs

This forum was archived on 2017-11-26.