When the content of the Email Greeting or the Postal Greeting field is getting too long, CiviCRM is no longer able to edit it through the GUI, what happened since I have activated Smarty and inserted large expressions.

I want to have a standard greeting that works for every gender, language and style.

This was working:

{capture assign=language}{contact.preferred_language}{/capture}{capture assign=prefix}{contact.individual_prefix}{/capture}{capture assign=style}{contact.communication_style}{/capture}
{if $style == 'Formal'} {if $language == 'fr_FR'}Cher{elseif $language == 'nl_NL'}Geachte{else}Dear{/if}  {$prefix|replace:'De heer':'heer'|replace:'De heren':'heren'|lower} {contact.last_name}{else}{if $language == 'fr_FR'}Bonjour{elseif $language == 'nl_NL'}Dag{else}Dear{/if} {contact.first_name}{/if} 

but the expression is getting too long when I try to add a test about the gender. As a work around, I decided to put this expression inside a file to be included by Smarty with this expression:

{include file='/usr/share/drupal/sites/default/files/my-greeting.tpl'}

but this doesn't work: nothing is included. The file /usr/share/drupal/sites/default/files/my-greeting.tpl has the correct ownership and permissions.

I would like to understand what I am doing wrong, and if it is possible to use this approach without opening a hole in the security of the system.

3 Answers 3


The length limit of the greetings syntax can be quite tricky, especially when using different languages with gender specific greetings.

Luckily there is the extension More Greetings that provides

  • additional greeting fields
  • no length limit for syntax
  • more possibilities such as using API calls in the syntax
  • a basic syntax checker
  • Interesting. The syntax checker also sounds like a more generally useful thing.
    – Demerit
    Mar 17, 2021 at 15:36
  • The extension is not listed in Home » CiviCRM » Administer CiviCRM » System Settings » Extensions. Where do I find a concise explanation for installing it from the downloaded ZIP file? Sorry for asking such a dumb question. Mar 17, 2021 at 20:34
  • 1
    OK, I found the answer to my question above: If you want to install a native CiviCRM extension which is not listed under Manage Extensions automatically: 1. Download the extension package from the download URL provided by the developer. 2. Unzip / untar the package and place it in your configured extensions directory. 3. If the package has been constructed properly - when you reload the Manage Extensions page the new extension should be listed with an Install link. Mar 17, 2021 at 20:51
  • 2
    We are in the process of getting the extension approved for automated distribution. This used to be complicated but there seems to be a better process now.
    – Fabian
    Mar 18, 2021 at 7:36
  • Once the extension is installed, I can see on each contact a list of new Greeting fields, but I don't understand how to build automatic Greetings that apply for all the contacts. It could be evident for people already knowing this extension, but in my eyes, there are gaping holes in the docs. The examples showing tpl code do not tell where to save these files. Mar 18, 2021 at 14:08

There's also the Salutations extension, which overlaps quite a bit with "More Greetings".

I have a significantly more feature-complete version of this extension in my Github, but because my version doesn't differentiate between addressee greetings and email/address greetings, it doesn't have a clean uninstall path. One day I'd like to resolve that and merge my changes in.

  • Thank you. For your infomation: I already installed the "More Greetings" extension and it seems to work. Mar 19, 2021 at 13:21

You should get an error about Smarty error: (secure mode) accessing ... is not allowed, although if you're using wordpress those messages just disappear unless you have php debugging turned on. But yes it won't let you use {include} that way.

What might work is to make a little smarty plugin, like the functionXXX ones in CRM/Core/Smarty/plugins, and then use that, e.g. function.myGreeting.php, and then use it like {myGreeting lang=$language}.

  • Interesting solution. Where do I find documentation for writing such a function, and where do I have to drop the corresponding file without losing it at every update of the system? Mar 17, 2021 at 20:35
  • 1
    Documentation is at smarty.net/docsv2/en/plugins.functions.tpl but I would just copy/paste one of the existing civi ones and edit it. For where to put it, it looks like civi will find it if you set a custom_php path at admin - system settings - directories and then put your smarty plugin file in a subfolder CRM/Core/Smarty/plugins under there. Or if you want to put it in an extension you might use hook_civicrm_config to add a path to CRM_Core_Smarty::singleton()->plugins_dir.
    – Demerit
    Mar 17, 2021 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.