Answers.Body: <p>First off, I realize I am <strong><em>extremely</em></strong> 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.</p>
  
  <p>What I did to find template variables when {debug} isn't working for a direct download etc was:</p>
  
  <p>In /CRM/Core/Smarty.php, Line 192 <em>temporarily</em> change</p>
  
  <pre><code>$this-&gt;security = TRUE;
  </code></pre>
  
  <p>to</p>
  
  <pre><code>$this-&gt;security = FALSE;
  </code></pre>
  
  <p>Let me emphasize that this is for a <strong>development environment ONLY</strong>. 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).</p>
  
  <p>Now we can call protected functions in our smarty templates to print out all template variables in several ways. I did it this way:</p>
  
  <pre><code>&lt;pre&gt;
  {php}print_r(CRM_Core_Smarty::get_template_vars());{/php}
  &lt;/pre&gt;
  </code></pre>
  
  <p>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):</p>
  
  <pre><code>{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}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-15T03:46:09.600Z
Answers.Text: Interesting! Could you share what you get outputted when you make it print out all the template variables?
Answers.UserDisplayName: Yongho Kim
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-08T18:04:37.247Z
Answers.LastActivityDate: 2018-06-08T18:04:37.247Z
Answers.UserDisplayName: Eli Lisseck
Body: <p>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:</p>
  
  <ul>
  <li>{$contribution.campaign_ID}</li>
  <li>{capture assign=project_id1}{contribution.campaign_id}{/capture}{$project_id1}</li>
  </ul>
  
  <p>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? </p>
  
  <p>Once I identify the campaign id, I'm hoping to run something like</p>
  
  <pre><code>{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}
  </code></pre>
  
  <p>So after searching further into the StackExchange I <a href="https://civicrm.stackexchange.com/questions/813/how-can-i-see-the-available-tokens-for-message-templates">found this</a>, 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.
  <a href="https://www.dropbox.com/s/lj6a9l8s6y0dp65/Smarty%20Debug.htm?dl=0" rel="nofollow noreferrer">Here is the cleaned up debug results</a>, 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.</p>
  
  <p>Here is the list of formats that didn't work. (It seemed that on some paratemers CiviCRM was case sensitive)</p>
  
  <pre><code>{$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}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-23T18:20:12.663Z
Comments.Text: 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!
Comments.UserDisplayName: Jon G - Megaphone Tech
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-23T22:50:04.863Z
Comments.Text: Thanks! The template name was "Contribution invoice Receipt" (Screenshot: http://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.
Comments.UserDisplayName: Yongho Kim
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-12-02T18:23:14.393Z
Comments.Text: 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?
Comments.UserDisplayName: Jon G - Megaphone Tech
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-12-20T18:20:30.583Z
Comments.Text: 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"?
Comments.UserDisplayName: Yongho Kim
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-12-21T13:56:50.410Z
Comments.Text: 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.
Comments.UserDisplayName: Jon G - Megaphone Tech
Tags: <civicontribute><tokens><message-templates><receipts><civicampaign>
Title: How to use Campaign ID (as a token) in Contribution Invoice/Email Receipt Template
ThreadText: # How to use Campaign ID (as a token) in Contribution Invoice/Email Receipt Template
  
  (Asked by: username_0 on 2016-11-22)
  
  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}
  
  **Tags:** civicontribute, tokens, message-templates, receipts, civicampaign
  
  > **Comments:**
  > **username_1**: 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!  
  > **username_0**: Thanks! The template name was "Contribution invoice Receipt" (Screenshot: http://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.  
  > **username_1**: 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?  
  > **username_0**: 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"?  
  > **username_1**: 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.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2018-06-08. Score: 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:
  
  {php}print_r(CRM_Core_Smarty::get_template_vars());{/php}
  
  
  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}
  
  > **Comments:**
  > **username_0**: Interesting! Could you share what you get outputted when you make it print out all the template variables?  
  
  ---
  
  