Answers.Body: <p>I might be missing something but, the <strong>contribution.contribution_id</strong> variable you are referring as a standalone variable I believe is a <strong>token</strong>, I can't figure out what's the smarty variable for it but you can do this (it works):</p>
  
  <pre><code>{capture assign='id'} // the variable
     {contribution.contribution_id} // here is the Contribution ID token
  {/capture}
  </code></pre>
  
  <p>And then your API call:</p>
  
  <pre><code>{crmAPI var='result' entity='Note' action='get' sequential=0 entity_table="civicrm_contribution" entity_id=$id}
  </code></pre>
  
  <p><strong>Update</strong>: final snippet should look like this, I've just tested it</p>
  
  <pre><code>{capture assign='id'}{contribution.contribution_id}{/capture}
  {crmAPI var='result' entity='Note' action='get' entity_table="civicrm_contribution" entity_id=$id}
  {foreach from=$result.values item=note}
    {$note.note}
  {/foreach}
  </code></pre>
  
  <p><a href="https://i.sstatic.net/fJDWm.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/fJDWm.png" alt="enter image description here"></a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-20T15:49:24.017Z
Answers.Text: I think you are correct, contribution.contribution_id is a token. I'm guessing that's the flaw in my thinking. I think I am confusing terms and might me confused between a token and a smarty variable?? When is it appropriate to use $variable.variable vs variable.variable? I couldn't get your code or Xavier's below to work so I'm guessing the case is that I can't use a token value in the smarty API call....
Answers.UserDisplayName: RayWright
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-20T15:58:19.190Z
Answers.Text: *edit to my above omment* upon reading I see your capture assign should make the civi token available to smarty. Ignore me while I continue testing, clearly I've got something set up wrong....
Answers.UserDisplayName: RayWright
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-20T16:40:57.243Z
Answers.Text: It totally works, I'm not sure why I had trouble at first. Thank you for your thoroughness - I now have a much better understanding of tokens and variables!
Answers.UserDisplayName: RayWright
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-20T16:50:42.903Z
Answers.Text: It's easy to confuse as both smarty and tokens are called using "{}" brackets, next step would be to create your own token for the contribution note
Answers.UserDisplayName: Andrei
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-20T16:55:45.487Z
Answers.Text: I actually did that first (I have eileens token extension installed because you can easily add your own tokens as well)- but had trouble pulling the Contribution # into the function. So since I knew it already it existed in my email I went the smarty way.
Answers.UserDisplayName: RayWright
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-21T08:43:36.000Z
Answers.Text: Hi, pretty sure {assign} works like the suggested {capture} code, but given that Andrei's solution works, I deleted my answer.
Answers.UserDisplayName: Xavier
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-21T09:54:03.817Z
Answers.Text: Hi @Xavier, in this case {assign} won't work because {contribution.contribution_id} is a **token** and not a smarty variable therefore even using `$smarty.ldelim - $smarty.rdelim` to place the token as the _assign value_  the token won't be called. Makes sense?
Answers.UserDisplayName: Andrei
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-21T09:55:48.997Z
Answers.Text: aah of course, thanks for the clarification.
Answers.UserDisplayName: Xavier
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-20T11:09:53.673Z
Answers.LastActivityDate: 2016-01-20T16:35:47.057Z
Answers.LastEditDate: 2016-01-20T16:35:47.057Z
Answers.UserDisplayName: Andrei
Body: <p>So I'm super close to getting a smarty variable working to place the contribution note in a thank you letter. </p>
  
  <p>I used the API explorer and got this far:</p>
  
  <pre><code>{crmAPI var='result' entity='Note' action='get' sequential=0 entity_table="civicrm_contribution" entity_id=$contribution.contribution_id}
  {foreach from=$result.values item=note}
    {$note.note}
  {/foreach}
  </code></pre>
  
  <p>But this prints a list of all contribution notes in the database, it doesn't filter out by the contribution ID. I know that the variable <strong>contribution.contribution_id</strong> works in the thank you letter as a standalone variable. I also can use the above code and substitute <code>entity_id=1</code>and that does print the note attached to contribution 1.</p>
  
  <p>How can I put a smarty variable inside the smarty variable api call??</p>
  
  <p>(Wordpress 4.3.2 and Civi 4.6.4)</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-20T03:40:52.640Z
Comments.Text: Funny, I'm fighting smartys for thank you letters as well.  I played with your code a bit and got odd results.  I selected four contacts.  Only one of them had a contribution note, the second one.  When I generated the pdf, the first had all the notes as you've noted but the rest of them were fine.  The second one listed the correct note and the others listed none as they should.  Also, it doesn't seem to be grabbing all the notes just some of them.  When I made the first contact the one with the note, its note wasn't listed in the list.
Comments.UserDisplayName: Paul-Tahoe
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-20T16:42:27.323Z
Comments.Text: @Paul-Tahoe are you selecting contributions and then running a thank you letter? You refer to contacts in your comment. Contact notes would be referenced differently than a note attached to a contribution.
Comments.UserDisplayName: RayWright
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-20T18:05:49.723Z
Comments.Text: Oops, I didn't word that very well.  I should have said I selected 4 contributions.  I'm doing a find contribution and running thank you letters.  I don't really need the contribution note but since I am in the middle of testing stuff and fighting smartys, it was easy to try your stuff partly to see if I could learn anything that might help me and partly to see if some of the things I've tried might work for you.
Comments.UserDisplayName: Paul-Tahoe
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-20T18:15:27.000Z
Comments.Text: No worries, just wanted to make sure we didn't further complicate the topic! I totally get fighting smartys and hoping someone else's post may illuminate your own problem. You'll probably see future posts of mine with more tokens and smarty problems/questions!
Comments.UserDisplayName: RayWright
Tags: <api><receipts><smarty>
Title: Contribution Note Smarty Variable
ThreadText: # Contribution Note Smarty Variable
  
  (Asked by: username_0 on 2016-01-20)
  
  So I'm super close to getting a smarty variable working to place the contribution note in a thank you letter.
  
  I used the API explorer and got this far:
  
  ```
  {crmAPI var='result' entity='Note' action='get' sequential=0 entity_table="civicrm_contribution" entity_id=$contribution.contribution_id}
  {foreach from=$result.values item=note}
    {$note.note}
  {/foreach}
  
  ```
  
  But this prints a list of all contribution notes in the database, it doesn't filter out by the contribution ID. I know that the variable **contribution.contribution\_id** works in the thank you letter as a standalone variable. I also can use the above code and substitute `entity_id=1`and that does print the note attached to contribution 1.
  
  How can I put a smarty variable inside the smarty variable api call??
  
  (Wordpress 4.3.2 and Civi 4.6.4)
  
  **Tags:** api, receipts, smarty
  
  > **Comments:**
  > **username_1**: Funny, I'm fighting smartys for thank you letters as well.  I played with your code a bit and got odd results.  I selected four contacts.  Only one of them had a contribution note, the second one.  When I generated the pdf, the first had all the notes as you've noted but the rest of them were fine.  The second one listed the correct note and the others listed none as they should.  Also, it doesn't seem to be grabbing all the notes just some of them.  When I made the first contact the one with the note, its note wasn't listed in the list.  
  > **username_0**: @username_1 are you selecting contributions and then running a thank you letter? You refer to contacts in your comment. Contact notes would be referenced differently than a note attached to a contribution.  
  > **username_1**: Oops, I didn't word that very well.  I should have said I selected 4 contributions.  I'm doing a find contribution and running thank you letters.  I don't really need the contribution note but since I am in the middle of testing stuff and fighting smartys, it was easy to try your stuff partly to see if I could learn anything that might help me and partly to see if some of the things I've tried might work for you.  
  > **username_0**: No worries, just wanted to make sure we didn't further complicate the topic! I totally get fighting smartys and hoping someone else's post may illuminate your own problem. You'll probably see future posts of mine with more tokens and smarty problems/questions!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2016-01-20. Score: 4 | Accepted answer
  
  I might be missing something but, the **contribution.contribution\_id** variable you are referring as a standalone variable I believe is a **token**, I can't figure out what's the smarty variable for it but you can do this (it works):
  
  ```
  {capture assign='id'} // the variable
     {contribution.contribution_id} // here is the Contribution ID token
  {/capture}
  
  ```
  
  And then your API call:
  
  ```
  {crmAPI var='result' entity='Note' action='get' sequential=0 entity_table="civicrm_contribution" entity_id=$id}
  
  ```
  
  **Update**: final snippet should look like this, I've just tested it
  
  ```
  {capture assign='id'}{contribution.contribution_id}{/capture}
  {crmAPI var='result' entity='Note' action='get' entity_table="civicrm_contribution" entity_id=$id}
  {foreach from=$result.values item=note}
    {$note.note}
  {/foreach}
  
  ```
  
  [![enter image description here](https://i.sstatic.net/fJDWm.png)](https://i.sstatic.net/fJDWm.png)
  
  > **Comments:**
  > **username_0**: I think you are correct, contribution.contribution_id is a token. I'm guessing that's the flaw in my thinking. I think I am confusing terms and might me confused between a token and a smarty variable?? When is it appropriate to use $variable.variable vs variable.variable? I couldn't get your code or username_3's below to work so I'm guessing the case is that I can't use a token value in the smarty API call....  
  > **username_0**: *edit to my above omment* upon reading I see your capture assign should make the civi token available to smarty. Ignore me while I continue testing, clearly I've got something set up wrong....  
  > **username_0**: It totally works, I'm not sure why I had trouble at first. Thank you for your thoroughness - I now have a much better understanding of tokens and variables!  
  > **username_2**: It's easy to confuse as both smarty and tokens are called using "{}" brackets, next step would be to create your own token for the contribution note  
  > **username_0**: I actually did that first (I have eileens token extension installed because you can easily add your own tokens as well)- but had trouble pulling the Contribution # into the function. So since I knew it already it existed in my email I went the smarty way.  
  > **username_3**: Hi, pretty sure {assign} works like the suggested {capture} code, but given that username_2's solution works, I deleted my answer.  
  > **username_2**: Hi @username_3, in this case {assign} won't work because {contribution.contribution_id} is a **token** and not a smarty variable therefore even using `$smarty.ldelim - $smarty.rdelim` to place the token as the _assign value_  the token won't be called. Makes sense?  
  > **username_3**: aah of course, thanks for the clarification.  
  
  ---
  
  