The "Extending Smarty" page at http://wiki.civicrm.org/confluence/display/CRMDOC/Extending+Smarty gives instructions for writing custom php functions and calling them from Smarty templates used in Pages, by using the pageRun hook to add a plugin directory to your template. But this doesn't work for Forms.

For example, a custom function works from the main Case dashboard, but not from the search view when filtering Cases by status.

How do I have the plugin directory included in Forms, not just Pages?

1 Answer 1


Use the config hook instead of pageRun. I originally had this hook in place, as per the example at "Extending Smarty":

function civicrm_pageRun(&$page) {
  $template = $page->getTemplate(); // retrieve Smarty template object
  array_push($template->plugins_dir, '/path/to/civi_custom/plugins');

I replaced that with:

function civicrm_config( &$config ) {
  $template =& CRM_Core_Smarty::singleton( );
  array_push($template->plugins_dir, '/path/to/civi_custom/plugins');

and now I can use my custom Smarty functions from both Pages and Forms.

  • Yeah, hook_civicrm_config makes more sense. I'll do a quick update to the wiki. If you come across another problem like this, consider updating the wiki. ;) Also, a relative path within the module/extension dir might be better -- consider using __DIR__.
    – Tim Otten
    Commented Jan 7, 2016 at 1:09

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.