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 CiviMail (Moderator: Piotr Szotkowski) »
  • Tokens and Smarty templates
Pages: [1]

Author Topic: Tokens and Smarty templates  (Read 1666 times)

werner

  • I’m new here
  • *
  • Posts: 21
  • Karma: 0
  • CiviCRM version: 4.5
  • CMS version: Drupal 6
  • MySQL version: mySQL 5
  • PHP version: php5
Tokens and Smarty templates
April 13, 2011, 06:50:28 am
Hi,

I somehow don't get the right code for a mail template. I want to create a different mail greeting depending on the gender of the person. So I tried the following code (german CiviCRM):

{if {contact.gender} == 'Weiblich' }Sehr geehrte Frau {elseif {contact.gender} == 'Männlich' }Sehr geehrter Herr {/if} {contact.first_name} {contact.last_name}

But all I get is a white screen .. I tried different things like ${contact.gender} but nothing really works. Any clue would be awesome

thanks werner
« Last Edit: April 13, 2011, 07:26:40 am by werner »

theMusician

  • I post occasionally
  • **
  • Posts: 48
  • Karma: 3
  • CiviCRM version: 4.0 and 4.0.1
  • CMS version: Drupal 7.0
  • MySQL version: MySQL 5.x
  • PHP version: 5.2
Re: Tokens and Smarty templates
April 15, 2011, 03:00:50 pm
Hi Werner,

http://wiki.civicrm.org/confluence/display/CRMDOC33/Smarty+in+mail+templates

This has an example of using a conditional with Smarty. Let us know if you are still running into problems.


fuerst

  • I’m new here
  • *
  • Posts: 6
  • Karma: 0
  • CiviCRM version: 3.4
  • CMS version: Drupal 6
  • MySQL version: 5.1
  • PHP version: 5.3
Re: Tokens and Smarty templates
June 16, 2011, 01:26:32 am
Access to the current contacts data is possible using the {$contact} array. It has the following structure:

$contact = array(
            contactId => array(contact data...)
           );

In CiviCRM 3.3 the template variable $contactId was available so it was possible to write a simple condition like this:

{if $contact.$contactId.gender_id == 1}Liebe{else}Lieber{/if}

In CiviCRM 3.4/4.0 $contactId seems to be gone. To get the contact data an additional loop is necessary:

{foreach from=$contact item=data}
  {if $data.gender_id == 1}Liebe{else}Lieber{/if}
{/foreach}


To see all available contact data elements you may print it out to the email/letter using {$contact|@debug_print_var}

Anyone know a better way to get the contact data in CiviCRM 3.4/4.0?

PS: Was not able to use the CODE-tag of that Forum because it produced the error message "Sorry, you are not allowed to post external links." when trying to post the posting.
« Last Edit: June 16, 2011, 01:31:15 am by fuerst »

fuerst

  • I’m new here
  • *
  • Posts: 6
  • Karma: 0
  • CiviCRM version: 3.4
  • CMS version: Drupal 6
  • MySQL version: 5.1
  • PHP version: 5.3
Re: Tokens and Smarty templates
June 16, 2011, 02:19:50 am
In addition to my comment above: The complete $contact array is available only when creating PDF letters. When sending an email the $contact array does contain a subset only. gender_id or gender is missing.

I also encountered when creating a PDF letter: Once you use a CiviCRM token the complete Smarty code will not be executed even it is still included in the compiled Smarty template.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMail (Moderator: Piotr Szotkowski) »
  • Tokens and Smarty templates

This forum was archived on 2017-11-26.