Altering Email Template in CiviCRM Module of Drupal
How to customize CiviCRM email templates using Smarty to merge data elements.
CiviCRM uses a server-side scripting language called Smarty in order to access server-side variables, perform logic and work with a template to generate a webpage. The overall flow is: All the business logic is done by PHP and all the presentation logic is done by Smarty. So the PHP pages do the database updates and selects, access session variables, create data structures particular webpage or email template and then hand over the data structures to a Smarty page. By the way, Smarty allows embedding of PHP code inside a webpage.
In this article, a simple task will be performed to illustrate the working of Smarty. The task is to change an email template that is tied to event registration. The change involved merging data elements.
Assume a scenario in which a user registers for an event and purchases 4 tickets for the entire family. The code generates a row for each person in the family that is registered for the event. Data is extracted from the array: $amount[i][“amount”], $amount[i][“label”], where i=0,1,2,3. Smarty code is written inside {…}. Amount contains the dollar value of ticket (there are different types of tickets—VIP, normal, etc.—of different amounts).
The above code creates, again, rows for each person in the family and lists firstName and lastName. The code additionally moves the value of ticket above the rows where first and last name are printed.