diff --git a/docs/framework/templates/extending-smarty.md b/docs/framework/templates/extending-smarty.md new file mode 100644 index 0000000000000000000000000000000000000000..c68b555fc6524c7612ea255e562eb691a043a7f7 --- /dev/null +++ b/docs/framework/templates/extending-smarty.md @@ -0,0 +1,52 @@ +# Extending Smarty + +The Smarty templating language that is used to output the HTML for +CiviCRM's templates is fairly powerful in its own right, but sometimes +it can't do everything you want. Smarty can be extended using "plugins" +-- you can find some examples and documentation online at [Smarty's +website](http://www.smarty.net){.external-link} or by searching the web. + +To install Smarty plugins without editing CiviCRM core (which is +difficult to maintain), you will have to implement the +hook_civicrm_config hook. (Activating hooks in Drupal and Joomla is +covered +[here](http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification#CiviCRMhookspecification-Proceduresforimplementinghooks%28forDrupal%29)). + +Once you've created your module or hook file, you can retrieve the +Smarty object and register your custom plugin path: + +<div class="code panel" style="border-width: 1px;"> + +<div class="codeContent panelContent"> + + function yourmodule_civicrm_config(&$config) { + $smarty = CRM_Core_Smarty::singleton(); + array_push($smarty->plugins_dir, __DIR__ . '/relative/path/to/custom/plugin/directory'); + } + +</div> + +</div> + +Then in that custom plugin directory, you can place whatever Smarty +plugins you need. + +You can also use this trick to change other Smarty behavior, such as +whether it can evaluate PHP placed directly in templates. For instance: + +<div class="code panel" style="border-width: 1px;"> + +<div class="codeContent panelContent"> + + function yourmodule_civicrm_config(&$config) { + $smarty = CRM_Core_Smarty::singleton(); + array_push($smarty->security_settings['MODIFIER_FUNCS'], 'explode'); // allow the explode() php function to be used as a "modifier" in Smarty templates + } + +</div> + +</div> + +However, be very careful with these settings – if you don't know what +you're doing, you can open security holes or create a mess of code +that's difficult to maintain. diff --git a/mkdocs.yml b/mkdocs.yml index fe3fc8c2956ccff63b7945863ac3cb19219bc550..e19cf6f5ac2a995de01fbf42f59dee97e4e8874c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -88,6 +88,7 @@ pages: - Template Reference: - Templates: framework/templates/index.md - Customizing templates: framework/templates/customizing.md + - Extending Smarty: framework/templates/extending-smarty.md - PseudoConstant Reference: framework/pseudoconstant.md # Other Reference: # CiviMail: /reference/civimail.md diff --git a/redirects/wiki-crmdoc.txt b/redirects/wiki-crmdoc.txt index 611eea21b3a64561b363c3458ae49c9c83b0d009..45fcf283a1a5eba286814702d19c82c56bb0ae9f 100644 --- a/redirects/wiki-crmdoc.txt +++ b/redirects/wiki-crmdoc.txt @@ -179,3 +179,4 @@ Backbone+Reference framework/backbone Extensions+and+Permissions security/permissions#extensions Customize+Built-in+Profile+Contribution+and+Event+Registration+Screens framework/templates/customizing Page+Templates framework/templates +Extending+Smarty framework/templates/extending-smarty