Answers.Body: <p>Use the config hook instead of pageRun.  I originally had this hook in place, as per the example at "Extending Smarty":</p>
  
  <pre><code>function civicrm_pageRun(&amp;$page) {
    $template = $page-&gt;getTemplate(); // retrieve Smarty template object
    array_push($template-&gt;plugins_dir, '/path/to/civi_custom/plugins');
  }
  </code></pre>
  
  <p>I replaced that with:</p>
  
  <pre><code>function civicrm_config( &amp;$config ) {
    $template =&amp; CRM_Core_Smarty::singleton( );
    array_push($template-&gt;plugins_dir, '/path/to/civi_custom/plugins');
  }
  </code></pre>
  
  <p>and now I can use my custom Smarty functions from both Pages and Forms.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-07T01:09:17.007Z
Answers.Text: 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__`.
Answers.UserDisplayName: Tim Otten
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-06T23:34:51.860Z
Answers.LastActivityDate: 2016-01-06T23:34:51.860Z
Answers.UserDisplayName: Norris
Body: <p>The "Extending Smarty" page at <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/Extending+Smarty" rel="nofollow">http://wiki.civicrm.org/confluence/display/CRMDOC/Extending+Smarty</a> 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.  </p>
  
  <p>For example, a custom function works from the main Case dashboard, but not from the search view when filtering Cases by status.</p>
  
  <p>How do I have the plugin directory included in Forms, not just Pages?</p>
  
Tags: <smarty>
Title: How do I use custom Smarty functions in a Form?
ThreadText: # How do I use custom Smarty functions in a Form?
  
  (Asked by: username_0 on 2016-01-06)
  
  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?
  
  **Tags:** smarty
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-01-06. Score: 2
  
  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.
  
  > **Comments:**
  > **username_1**: 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__`.  
  
  ---
  
  