Answers.Body: <p>It doesn't work because <code>$lineItem</code> is not set in the template, you'll have to loop thorough <code>$contribtuions</code> and use the API:</p>
  
  <pre><code>{foreach from=$contributions item=contribution}
  {crmAPI var='result' entity='LineItem' action='get' contribution_id=$contribution.id} 
    {foreach from=$result.values item=lineitem} 
      {$lineitem.label} // Price field label
    {/foreach}
  {/foreach}
  </code></pre>
  
  <p><strong>Please note</strong>: this works fine generating ThankYou's with one contribution per individual.</p>
  
  <p>Related topics for more details:</p>
  
  <ul>
  <li><a href="https://civicrm.stackexchange.com/q/9131/872">How can I use custom tokens when grouping Thank You letters</a></li>
  <li><a href="https://civicrm.stackexchange.com/q/8985/872">Contribution Note Smarty Variable</a></li>
  </ul>
  
  <p>Let me know if that helps.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-13T20:45:45.037Z
Answers.Text: This is it, thanks!  I'll just add for others that once the line item is loaded into the array  $lineitem then its easy to access all the elements of the price field (or columns in the database table civicrm_line_item). $lineitem.label is the label, $lineitem.qty is the quantity, etc.
Answers.UserDisplayName: Eliot Mason
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-15T20:41:14.393Z
Answers.Text: Glad it help Eliot, if the answer is correct perhaps you could mark it answered, other people might find it useful.
Answers.UserDisplayName: Andrei
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-11T12:19:17.550Z
Answers.LastActivityDate: 2016-02-11T12:19:17.550Z
Answers.LastEditDate: 2017-04-13T12:53:13.017Z
Answers.UserDisplayName: Andrei
Body: <p>We have a need to display price field information in a contribution Thank You letter.  As the token system can't handle the price set data, I've pulled the relevant Smarty code from the receipt template, which very nicely presents all of the price fields that were selected for the contribution.</p>
  
  <p>Of course when I make PDFs, its not working : )</p>
  
  <p>I have Smarty enabled for email in the settings.php, and I can use Smarty logic to display content in the Thank You - so Smarty is actually working. But the beginning loop "{foreach from=$lineItem item=value key=priceset}" seems to return nothing and thus no price fields are added to the letter.</p>
  
  <p>Is this possible to do?  What is needed to activate processing of price fields in a letter?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-02-10T20:08:11.413Z
Comments.Text: I'll add that I took all the code from the contribution receipt and dropped it into a Thank You letter, just as a test of my code. The result is a blank page.
Comments.UserDisplayName: Eliot Mason
Tags: <contributions><message-templates><smarty>
Title: How to include price field data in a Contribution Thank You letter
ThreadText: # How to include price field data in a Contribution Thank You letter
  
  (Asked by: username_0 on 2016-02-10)
  
  We have a need to display price field information in a contribution Thank You letter. As the token system can't handle the price set data, I've pulled the relevant Smarty code from the receipt template, which very nicely presents all of the price fields that were selected for the contribution.
  
  Of course when I make PDFs, its not working : )
  
  I have Smarty enabled for email in the settings.php, and I can use Smarty logic to display content in the Thank You - so Smarty is actually working. But the beginning loop "{foreach from=$lineItem item=value key=priceset}" seems to return nothing and thus no price fields are added to the letter.
  
  Is this possible to do? What is needed to activate processing of price fields in a letter?
  
  **Tags:** contributions, message-templates, smarty
  
  > **Comments:**
  > **username_0**: I'll add that I took all the code from the contribution receipt and dropped it into a Thank You letter, just as a test of my code. The result is a blank page.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-02-11. Score: 3 | Accepted answer
  
  It doesn't work because `$lineItem` is not set in the template, you'll have to loop thorough `$contribtuions` and use the API:
  
  ```
  {foreach from=$contributions item=contribution}
  {crmAPI var='result' entity='LineItem' action='get' contribution_id=$contribution.id} 
    {foreach from=$result.values item=lineitem} 
      {$lineitem.label} // Price field label
    {/foreach}
  {/foreach}
  
  ```
  
  **Please note**: this works fine generating ThankYou's with one contribution per individual.
  
  Related topics for more details:
  
  * [How can I use custom tokens when grouping Thank You letters](https://civicrm.stackexchange.com/q/9131/872)
  * [Contribution Note Smarty Variable](https://civicrm.stackexchange.com/q/8985/872)
  
  Let me know if that helps.
  
  > **Comments:**
  > **username_0**: This is it, thanks!  I'll just add for others that once the line item is loaded into the array  $lineitem then its easy to access all the elements of the price field (or columns in the database table civicrm_line_item). $lineitem.label is the label, $lineitem.qty is the quantity, etc.  
  > **username_1**: Glad it help username_0, if the answer is correct perhaps you could mark it answered, other people might find it useful.  
  
  ---
  
  