Answers.Body: <p>You can use Smarty in greetings handling.  So first - make sure you're using the &quot;Email Greeting&quot; or &quot;Postal Greeting&quot; token instead of the &quot;First Name&quot; etc. tokens.</p>
  <p>Then you can do something like this:</p>
  <pre><code>{capture assign=ln}{contact.last_name}{/capture}{if $ln ==&quot;&quot;}{contact.custom_1}{else}{contact.last_name}{/if}
  </code></pre>
  <p>See <a href="https://civicrm.org/blog/antrik/enhancing-greetings-handling" rel="nofollow noreferrer">this blog post on greetings handling</a> for more detail.</p>
  <p>EDIT: This approach won't work if you need accented characters because of how Smarty works.  See <a href="https://www.dxsdata.com/2014/05/php-smarty-empties-strings-with-special-characters/" rel="nofollow noreferrer">https://www.dxsdata.com/2014/05/php-smarty-empties-strings-with-special-characters/</a> for details.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-16T18:48:36.863Z
Answers.Text: I am quite a beginner I guess, as I read through that page but its still unclear where I should put this smarty code? That post says this: admin/options/postal_greeting but that doesn't exist:-( Is it under admin/communication/email greeting formats? Or should it go at each contacts communication preferences? Or in option groups under system settings?
Answers.UserDisplayName: user3635986
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-16T22:24:37.703Z
Answers.Text: @andras Note that the Smarty I wrote is only an approximation!  Translated, it says, "If 'last name' doesn't exist, use the value of the custom field with an ID of '1', otherwise use the last name".  Not exactly what you want!  To test this, you can click on a single contact's postal greeting and select "Customized".  Enter the Smarty there, test until you're happy.  Once you're done, the correct place to look is **Administer menu » Communications » Postal Greeting Formats** (or **Email Greeting Formats**).
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-17T11:16:53.103Z
Answers.Text: What I understand here is that this script chooses between last name and a custom field that in my case would be the full name. But I still don't get what to do when both are missing. Where do I set this to fall back on a word like "Supporter" when I have nothing but an email of a contact.
Answers.UserDisplayName: user3635986
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-17T12:54:19.603Z
Answers.Text: Wow, I almost did it! It works with english characters, Now, the next problem is when I have a special character in the hungarian version of supporter; the letter "ü" and that is causing problems, namely I cannot save the contact if I choose this smarty string. If I get rid of the special character it works nicely, but any non-english character seems prohibited:-(
Answers.UserDisplayName: user3635986
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-19T14:07:36.500Z
Answers.Text: Let me further elaborate here. I can even save the default greeting under email formats, but if it has any non english letters, then if I want to change a contact to use this new type of greeting it cannot be saved, it's giving me error 500 or a message that it cannot connect to the server(?!) Removing the special character allows me so save. I tried using &uuml; instead of "ü" to no avail:-(
Answers.UserDisplayName: user3635986
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-19T19:33:31.220Z
Answers.Text: @andras That sounds like it's a problem with your MySQL collation, and not with this particular feature.  Can you save Hungarian characters in other fields?
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-19T19:47:14.743Z
Answers.Text: Yes, I can use special characters even in the email greetings and all over the place. But when I put these characters in the default bit in the smarty code thats where is fails. This example will not work and gives 500 errror on saving at contacts: {capture assign=fullname}{contact.custom_17}{/capture}Tisztelt {$fullname|default:Partnerünk}!
Answers.UserDisplayName: user3635986
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-19T21:00:18.173Z
Answers.Text: @andras Please see if the problem exists on the "master" branch by replicating the problem here: https://dmaster.demo.civicrm.org.  If you get the same error, please open a ticket on https://lab.civicrm.org to report the issue - or just report back here that the problem exists on the master branch, along with exact steps to replicate, and I'll file a ticket.
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-19T21:42:12.327Z
Answers.Text: I just tried now, but I don't know how to edit the civicrm.settings.php in dmaster version, and turn on smarty in there as I did on my installation. (define( 'CIVICRM_MAIL_SMARTY', 1 );) So that might be the reason I am getting another error message: User error: Smarty error: [in string:{capture assign=teljes}{/capture}Tisztelt {$teljes|default:Partnerünk}! line 1]: syntax error: unrecognized tag: $teljes|default:Partnerünk (Smarty_Compiler.class.php, line 441) in Smarty->trigger_error() (line 1100 of /srv/buildkit/build/dmaster/web/sites/all/modules/civicrm/packages/Smarty/Smarty.class.php)
Answers.UserDisplayName: user3635986
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-19T21:42:20.520Z
Answers.Text: and this too: User error: Smarty error: [in string:{capture assign=teljes}{/capture}Tisztelt {$teljes|default:Partnerünk}! line 1]: syntax error: unrecognized tag '' (Smarty_Compiler.class.php, line 585) in Smarty->trigger_error() (line 1100 of /srv/buildkit/build/dmaster/web/sites/all/modules/civicrm/packages/Smarty/Smarty.class.php).
Answers.UserDisplayName: user3635986
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-20T06:54:15.773Z
Answers.Text: If I use {capture assign=fullname}{contact.custom_17}{/capture}Tisztelt {$fullname|default:Partnerunk}! it works. If I use:  {capture assign=fullname}{contact.custom_17}{/capture}Tisztelt {$fullname|default:Partnerünk}! the default greeting is empty. I even tried putting &uuml; instead of ü and that gives the error message above.
Answers.UserDisplayName: user3635986
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-20T14:21:00.497Z
Answers.Text: @andras - I edited my answer to reflect that I don't think this approach will work for you.  Also note that you don't need to enable `CIVICRM_MAIL_SMARTY` to use Smarty in greetings.  I think you'll need to define a new token with an extension to solve your issue.
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-20T14:58:14.573Z
Answers.Text: Well, I guess I need to learn something new here. At the moment I have no idea what this "define a new token" is about and what extension I could use. Can I ask for some directions?
Answers.UserDisplayName: user3635986
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-20T15:23:42.670Z
Answers.Text: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/106953/discussion-between-andras-and-jon-g-megaphone-tech).
Answers.UserDisplayName: user3635986
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-16T17:45:22.980Z
Answers.LastActivityDate: 2022-11-21T15:45:13.720Z
Answers.LastEditDate: 2022-11-21T15:45:13.720Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>What if I don't have First name/last name but only a custom field called "full name" How to display that field or if thats missing display: "Supporter" instead?</p>
  
Tags: <tokens>
Title: use of "Dear you" extension when there is no first/last name only email and custom name field
ThreadText: # use of "Dear you" extension when there is no first/last name only email and custom name field
  
  (Asked by: username_0 on 2020-04-16)
  
  What if I don't have First name/last name but only a custom field called "full name" How to display that field or if thats missing display: "Supporter" instead?
  
  **Tags:** tokens
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-04-16. Score: 2 | Accepted answer
  
  You can use Smarty in greetings handling. So first - make sure you're using the "Email Greeting" or "Postal Greeting" token instead of the "First Name" etc. tokens.
  
  Then you can do something like this:
  
  ```
  {capture assign=ln}{contact.last_name}{/capture}{if $ln ==""}{contact.custom_1}{else}{contact.last_name}{/if}
  
  ```
  
  See [this blog post on greetings handling](https://civicrm.org/blog/antrik/enhancing-greetings-handling) for more detail.
  
  EDIT: This approach won't work if you need accented characters because of how Smarty works. See <https://www.dxsdata.com/2014/05/php-smarty-empties-strings-with-special-characters/> for details.
  
  > **Comments:**
  > **username_0**: I am quite a beginner I guess, as I read through that page but its still unclear where I should put this smarty code? That post says this: admin/options/postal_greeting but that doesn't exist:-( Is it under admin/communication/email greeting formats? Or should it go at each contacts communication preferences? Or in option groups under system settings?  
  > **username_1**: @andras Note that the Smarty I wrote is only an approximation!  Translated, it says, "If 'last name' doesn't exist, use the value of the custom field with an ID of '1', otherwise use the last name".  Not exactly what you want!  To test this, you can click on a single contact's postal greeting and select "Customized".  Enter the Smarty there, test until you're happy.  Once you're done, the correct place to look is **Administer menu » Communications » Postal Greeting Formats** (or **Email Greeting Formats**).  
  > **username_0**: What I understand here is that this script chooses between last name and a custom field that in my case would be the full name. But I still don't get what to do when both are missing. Where do I set this to fall back on a word like "Supporter" when I have nothing but an email of a contact.  
  > **username_0**: Wow, I almost did it! It works with english characters, Now, the next problem is when I have a special character in the hungarian version of supporter; the letter "ü" and that is causing problems, namely I cannot save the contact if I choose this smarty string. If I get rid of the special character it works nicely, but any non-english character seems prohibited:-(  
  > **username_0**: Let me further elaborate here. I can even save the default greeting under email formats, but if it has any non english letters, then if I want to change a contact to use this new type of greeting it cannot be saved, it's giving me error 500 or a message that it cannot connect to the server(?!) Removing the special character allows me so save. I tried using &uuml; instead of "ü" to no avail:-(  
  > **username_1**: @andras That sounds like it's a problem with your MySQL collation, and not with this particular feature.  Can you save Hungarian characters in other fields?  
  > **username_0**: Yes, I can use special characters even in the email greetings and all over the place. But when I put these characters in the default bit in the smarty code thats where is fails. This example will not work and gives 500 errror on saving at contacts: {capture assign=fullname}{contact.custom_17}{/capture}Tisztelt {$fullname|default:Partnerünk}!  
  > **username_1**: @andras Please see if the problem exists on the "master" branch by replicating the problem here: https://dmaster.demo.civicrm.org.  If you get the same error, please open a ticket on https://lab.civicrm.org to report the issue - or just report back here that the problem exists on the master branch, along with exact steps to replicate, and I'll file a ticket.  
  > **username_0**: I just tried now, but I don't know how to edit the civicrm.settings.php in dmaster version, and turn on smarty in there as I did on my installation. (define( 'CIVICRM_MAIL_SMARTY', 1 );) So that might be the reason I am getting another error message: User error: Smarty error: [in string:{capture assign=teljes}{/capture}Tisztelt {$teljes|default:Partnerünk}! line 1]: syntax error: unrecognized tag: $teljes|default:Partnerünk (Smarty_Compiler.class.php, line 441) in Smarty->trigger_error() (line 1100 of /srv/buildkit/build/dmaster/web/sites/all/modules/civicrm/packages/Smarty/Smarty.class.php)  
  > **username_0**: and this too: User error: Smarty error: [in string:{capture assign=teljes}{/capture}Tisztelt {$teljes|default:Partnerünk}! line 1]: syntax error: unrecognized tag '' (Smarty_Compiler.class.php, line 585) in Smarty->trigger_error() (line 1100 of /srv/buildkit/build/dmaster/web/sites/all/modules/civicrm/packages/Smarty/Smarty.class.php).  
  > **username_0**: If I use {capture assign=fullname}{contact.custom_17}{/capture}Tisztelt {$fullname|default:Partnerunk}! it works. If I use:  {capture assign=fullname}{contact.custom_17}{/capture}Tisztelt {$fullname|default:Partnerünk}! the default greeting is empty. I even tried putting &uuml; instead of ü and that gives the error message above.  
  > **username_1**: @andras - I edited my answer to reflect that I don't think this approach will work for you.  Also note that you don't need to enable `CIVICRM_MAIL_SMARTY` to use Smarty in greetings.  I think you'll need to define a new token with an extension to solve your issue.  
  > **username_0**: Well, I guess I need to learn something new here. At the moment I have no idea what this "define a new token" is about and what extension I could use. Can I ask for some directions?  
  > **username_0**: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/106953/discussion-between-andras-and-jon-g-megaphone-username_1).  
  
  ---
  
  