Answers.Body: <p>You will need to set CIVICRM_MAIL_SMARTY to 1 in civicrm.settings.php file to execute smarty logics. And then can use below code in your message template</p>
  <pre><code>{capture assign=contactName}{contact.first_name}{/capture}
  {if $contactName}{$contactName}{else}{ts}Friend{/ts}{/if}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-11-21T22:36:11.350Z
Answers.Text: Thank you so much!  I know we are already using smarty in other templates so hopefully I can just use this code as is!
Answers.UserDisplayName: erin
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-11-21T22:38:32.533Z
Answers.Text: Spoke too soon - the subject line has a character limit of 128 so I don't think this can be done
Answers.UserDisplayName: erin
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-11-21T22:57:24.740Z
Answers.Text: In recent versions of civi and with flexmailer you don't need the capture part anymore, you just have to put quotes around the token in the `if`, e.g. try `{if '{contact.first_name}'}{contact.first_name}{else}{ts}Friend{/ts}{/if}`
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-11-22T15:54:49.250Z
Answers.Text: If you are on latest Civi you can remove the capture section, hopefully that should reduce the chars
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-11-21T22:06:59.310Z
Answers.LastActivityDate: 2022-11-21T22:06:59.310Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>I know nothing about smarty (it's on my to do list to start learning!) and I'm wondering if it is possible to do something like this in the message subject (or message body) of a bulk email:</p>
  <p>If {contact.first_name} is blank<br />
  Then &quot;Friend&quot;
  else {contact.first_name}?</p>
  
Tags: <civimail><smarty>
Title: Smarty code in email message subject
ThreadText: # Smarty code in email message subject
  
  (Asked by: username_0 on 2022-11-21)
  
  I know nothing about smarty (it's on my to do list to start learning!) and I'm wondusername_0g if it is possible to do something like this in the message subject (or message body) of a bulk email:
  
  If {contact.first\_name} is blank  
  Then "Friend"
  else {contact.first\_name}?
  
  **Tags:** civimail, smarty
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-11-21. Score: 1 | Accepted answer
  
  You will need to set CIVICRM_MAIL_SMARTY to 1 in civicrm.settings.php file to execute smarty logics. And then can use below code in your message template
  {capture assign=contactName}{contact.first_name}{/capture}
  {if $contactName}{$contactName}{else}{ts}Friend{/ts}{/if}
  
  > **Comments:**
  > **username_0**: Thank you so much!  I know we are already using smarty in other templates so hopefully I can just use this code as is!  
  > **username_0**: Spoke too soon - the subject line has a character limit of 128 so I don't think this can be done  
  > **username_2**: In recent versions of civi and with flexmailer you don't need the capture part anymore, you just have to put quotes around the token in the `if`, e.g. try `{if '{contact.first_name}'}{contact.first_name}{else}{ts}Friend{/ts}{/if}`  
  > **username_1**: If you are on latest Civi you can remove the capture section, hopefully that should reduce the chars  
  
  ---
  
  