0

I've been trying to figure this out for myself but I am super frustrated at this point! I've got smarty variables and conditional statements working in thank you letters. Well kind of working. Basically I'd like to include the contribution note if the note field is filled in, if it's not show the text "None". I can get the note to display but no matter what set up I've used I can't get it to show "None". I have two donations one with a note, one without. Here is what I've tried so far:

{if $note.note}I'm a note{/if} // works as expected
{if !$note.note}None{/if} // does NOT show the text none as expected

{if $note.note neq""}I'm a note{/if} // works as expected
{if $note.note eq""}None{/if} // does NOT show the text none as expected

{if $note.note}I'm a note{else}None{/if} // outputs "I'm a note" on contribution receipt with a note but still nothing on the contribution that has no note.

{if !$note.note}None{else}I'm a note{/if} // outputs "I'm a note" on contribution receipt with a note but still nothing on the contribution that has no note.

I've also tried capturing a smarty variable and then using it in the if statement.

{capture assign='note_text'}None{/capture}
{if !$note.note}{$note_text}{else}I'm a note{/if} // "None" is still not displayed as it should be.

Can anyone shed some light? (I'm sure a suggestion will be is to write some hook or custom token with this logic already worked in. But I'd really like to know why the if statement isn't working as straightforward as I'd imagined it would. I'd like to use more if statements for mailing labels etc and if I can't get an "else" to work that's a problem.)

(Wordpress 4.4.1 and Civi 4.6.4)

1

That's a good one, so if the contribution has no Note, no note record is created in the contribution table therefore the result is an empty array, I'm not sure of why none of your code is working, I believe is because the array is already initialized and smarty returns TRUE?

Workaround:

{assign var='note_count' value=$result.count} // grab the api count result
{if !$note_count}Contribution note: None // Print if there's no note...
{elseif $note_count} // else...
{foreach from=$result.values item=note} 
  Contribution note: {$note.note}
{/foreach}
{/if}

Let me know how that goes.

  • That's it! Thanks for explaining why it was not showing results this will help as I continue to develop the thank you letter! – RayWright Jan 22 '16 at 14:18
  • I am unsuccessfully trying to apply this to the transaction ID field in a donation thank you letter. Any ideas? – Yossi Dec 21 '17 at 6:01
  • @Yossi assuming that transactionID is your variable name, you can try something like {if not $transactionID|empty}Transaction Id: {$transactionID}{else}Transaction Id: none{/if} – Andrei Dec 21 '17 at 10:29
  • Thanks @Andrei. TransactionID is my variable but that didn't work, just renders a blank page – Yossi Dec 21 '17 at 18:03
  • @Yossi I suggest you ask a new question to describe your case and the problem your having, difficult to tell without any further detail – Andrei Dec 22 '17 at 9:52
1

Try this:

{if "{note.note}" eq ""}None{/if}

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.