2

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=1and 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)

  • 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. – Paul-Tahoe Jan 20 '16 at 3:40
  • @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. – RayWright Jan 20 '16 at 16:42
  • 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. – Paul-Tahoe Jan 20 '16 at 18:05
  • 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! – RayWright Jan 20 '16 at 18:15
4

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

  • 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.... – RayWright Jan 20 '16 at 15:49
  • 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.... – RayWright Jan 20 '16 at 15:58
  • 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! – RayWright Jan 20 '16 at 16:40
  • 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 – Andrei Jan 20 '16 at 16:50
  • 1
    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? – Andrei Jan 21 '16 at 9:54

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.