2

We use Campaign ID (renamed using Word Replacer to "Project ID") to categorize different kinds of contributions. Some come in through online contribution pages, and some are entered manually on CiviCRM after we receive cash or checks. I am customizing the "Contribution Invoice Receipt" system workflow message, and I tried to show the Campaign ID by using:

  • {$contribution.campaign_ID}
  • {capture assign=project_id1}{contribution.campaign_id}{/capture}{$project_id1}

None of these pull up the Campaign ID. And how come there are already contribution related fields in place in the template, such as $contribution_status_id or $amount? Is there a full list of fields available somewhere?

Once I identify the campaign id, I'm hoping to run something like

{if $campaignid==15}
Thanks for donating to Project 15! Bla bla (custom text)
{elseif $campaignid=17}
Thanks for becoming a member! Bla bla! (custom text)
{else}
Thanks for your donation! Bla bal (generic text)
{/if}

So after searching further into the StackExchange I found this, which shows you can get the full list by inserting {debug} into the template, then the template outcome will show it as an email Javascript when viewing the source. Here is the cleaned up debug results, which indicates that the token to use may be $formValues.campaign_id. I then tested it, and turns out that it works on Contributions - Receipt (offline) and online, but not in Print Invoice.

Here is the list of formats that didn't work. (It seemed that on some paratemers CiviCRM was case sensitive)

{$contribution.campaign_ID}
{$contribution.campaign_id}
{$contribution.campaign_Id}
{$contribution.project_ID}
{$contribution.project_id}
{$contribution.project_Id}
{$contribution_campaign_id}
{$contribution_campaign_ID}
{$formValues.campaign_id}
{$formvalues.campaign_id}
{$formTpl.campaign_id}
{$campaign_id}
{$contributionProjectId}
{$projectId}
{$ProjectId}
{$contribution_Project_Id}
{$contributionCammpaignId}
{$campaignId}
{$CampaignId}
{$campaignid}
{$contribution_campaign_id}
{capture assign=project_id1}{contribution.campaign_id}{/capture}
{capture assign=project_id2}{contribution.Campaign_Id}{/capture}
{capture assign=project_id3}{contribution.campaign_Id}{/capture}
{capture assign=project_id4}{formvalues.campaign_id}{/capture}
{capture assign=project_id5}{formValues.campaign_id}{/capture}
{$project_id1} {$project_id2}  {$project_id3}{$project_id4}{$project_id5}
{$contributioncampaignID}
{$value.campaign_id}
{$formValues.33}
{formValues.campaign_id}
  • Welcome to Stack Exchange! Two responses: First - I see both "Contributions - Receipt (off-line)" and "Contributions - Receipt (on-line)" in Mailings » Message Templates but not "Print Invoice", so could you please edit your question to indicate where you're looking? Second - it appears you answered your own first question but then asked a second question. Stack Exchange isn't a forum - it works best as a Q&A site when there's one question per post. Just for future reference! – Jon G - Megaphone Tech Nov 23 '16 at 18:20
  • Thanks! The template name was "Contribution invoice Receipt" (Screenshot: i.imgur.com/gIKde0X.png). I had customized the name of the template as well and I couldn't remember what the original name was. – Yongho Kim Nov 23 '16 at 22:50
  • The list of variables available depends on the template you're using. Your link to the Smarty HTML on Dropbox isn't accessible to me (I don't have Dropbox). Is it a list of variables for the "Contribution - Invoice" template, or a different template? – Jon G - Megaphone Tech Dec 2 '16 at 18:23
  • It's a list of variables for a different template, "Contributions - Receipt (offline). The "Contribution - Invoice" template does not generate an email, and using {debug} doesn't generate a hidden annotation like for the email ones. How can I view the variables list for PDF generating templates like "Contributions - Invoice"? – Yongho Kim Dec 20 '16 at 18:20
  • That's a good question! I tried but couldn't figure it out quickly. You may want to ask that as a separate question. Since I know you have a relationship with my former employer (Palante), you may also want to pay them to research it. – Jon G - Megaphone Tech Dec 21 '16 at 13:56
1

First off, I realize I am extremely late to the party - but I just read this question in the midst of trying to resolve a similar issue where I needed to know what template variables are available to a PDF template.

What I did to find template variables when {debug} isn't working for a direct download etc was:

In /CRM/Core/Smarty.php, Line 192 temporarily change

$this->security = TRUE;

to

$this->security = FALSE;

Let me emphasize that this is for a development environment ONLY. Please please please under no circumstances do this on a production site (you are turning off very important security features, I cannot emphasize that enough).

Now we can call protected functions in our smarty templates to print out all template variables in several ways. I did it this way:

<pre>
{php}print_r(CRM_Core_Smarty::get_template_vars());{/php}
</pre>

From a quick glance at that, it didn't look to me like campaign information is available to this template already, and it looked like contribution_id is only available under 'line_item'... so I would put something like this in the message template (check out /civicrm/api/explorer for more examples):

{foreach from=$lineItem item=value key=priceset}
  {crmAPI var='result' entity='Contribution' action='getsingle' sequential=0 return='campaign_id' id=`$value.contribution_id`}
    {foreach from=$result item=youritem}
      {$youritem.campaign_id}
      {$youritem.contribution_campaign_title}
  {/foreach}
{/foreach}
  • Interesting! Could you share what you get outputted when you make it print out all the template variables? – Yongho Kim Jun 15 '18 at 3:46

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.