Answers.Body: <p>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?</p>
  
  <p><strong>Workaround</strong>:</p>
  
  <pre><code>{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}
  </code></pre>
  
  <p>Let me know how that goes.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-22T14:18:57.073Z
Answers.Text: That's it! Thanks for explaining why it was not showing results this will help as I continue to develop the thank you letter!
Answers.UserDisplayName: RayWright
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-21T06:01:49.380Z
Answers.Text: I am unsuccessfully trying to apply this to the transaction ID field in a donation thank you letter. Any ideas?
Answers.UserDisplayName: Yossi
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-21T10:29:07.323Z
Answers.Text: @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}`
Answers.UserDisplayName: Andrei
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-21T18:03:46.307Z
Answers.Text: Thanks @Andrei. TransactionID is my variable but that didn't work, just renders a blank page
Answers.UserDisplayName: Yossi
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-22T09:52:26.653Z
Answers.Text: @Yossi I suggest you ask a new question to describe your case and the problem your having, difficult to tell without any further detail
Answers.UserDisplayName: Andrei
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-22T13:31:38.370Z
Answers.LastActivityDate: 2016-01-22T13:31:38.370Z
Answers.UserDisplayName: Andrei
Answers.Body: <p>Try this:</p>
  
  <pre><code>{if "{note.note}" eq ""}None{/if}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-22T08:18:27.540Z
Answers.LastActivityDate: 2016-01-22T08:18:27.540Z
Answers.UserDisplayName: Paul-Tahoe
Body: <p>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:</p>
  
  <pre><code>{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.
  </code></pre>
  
  <p>I've also tried capturing a smarty variable and then using it in the if statement.</p>
  
  <pre><code>{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.
  </code></pre>
  
  <p>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.)</p>
  
  <p>(Wordpress 4.4.1 and Civi 4.6.4)</p>
  
Tags: <tokens><message-templates><smarty>
Title: If statement not working if the smarty variable is not set
ThreadText: # If statement not working if the smarty variable is not set
  
  (Asked by: username_0 on 2016-01-22)
  
  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)
  
  **Tags:** tokens, message-templates, smarty
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2016-01-22. Score: 1 | Accepted answer
  
  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.
  
  > **Comments:**
  > **username_0**: That's it! Thanks for explaining why it was not showing results this will help as I continue to develop the thank you letter!  
  > **username_2**: I am unsuccessfully trying to apply this to the transaction ID field in a donation thank you letter. Any ideas?  
  > **username_1**: @username_2 assuming that `transactionID` is your variable name, you can try something like `{if not $transactionID|empty}Transaction Id: {$transactionID}{else}Transaction Id: none{/if}`  
  > **username_2**: Thanks @username_1. TransactionID is my variable but that didn't work, just renders a blank page  
  > **username_1**: @username_2 I suggest you ask a new question to describe your case and the problem your having, difficult to tell without any further detail  
  
  ---
  
  ### Answer by username_3 on 2016-01-22. Score: 1
  
  Try this:
  
  ```
  {if "{note.note}" eq ""}None{/if}
  
  ```
  
  
  ---
  
  