Answers.Body: <p>I often use the buildForm hook to modify data that is then passed to Smarty, or even add my own Smarty variables to the form.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-22T06:54:22.777Z
Answers.Text: I'll have to try that again, I could see the variables in Smarty but directly modifying them in the form didn't affect the output. If it's not something specific to that tpl, I might need to brush up on my QuickForm :)
Answers.UserDisplayName: Chris Burgess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-22T06:51:41.493Z
Answers.LastActivityDate: 2015-10-22T06:51:41.493Z
Answers.UserDisplayName: ErikH - CiviCooP
Answers.Body: <p>Just adding an example to the solution of Erik Hommel. It removes a <em>create activity link</em></p>
  
  <pre><code>function &lt;&lt;your extension&gt;&gt;_civicrm_buildForm($formName, &amp;$form) {
  
    if($formName == 'CRM_Activity_Form_ActivityLinks') { 
       $activityTypes = $form-&gt;get_template_vars('activityTypes');
       $ActityToRemoveKey = array_search('ActityToRemove', $activityTypes);
       if(isset($ActityToRemoveKey )){
       unset($activityTypes[$claimKey]);
       }
       $form-&gt;assign('activityTypes',$activityTypes);
    }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-18T09:54:16.580Z
Answers.LastActivityDate: 2017-04-18T09:54:16.580Z
Answers.UserDisplayName: Kainuk - CiviCooP
Body: <p>Recently I needed to modify Smarty variables being passed into a template from an extension. I tried a couple of likely hooks, but neither of them seemed to provide this functionality. The templates in question were Confirm.tpl from various locations.</p>
  
  <p>Is there hook functionality (akin to Drupal's preprocess functions) which permits adjusting variables in templates?</p>
  
  <hr>
  
  <p>Background: for the eWay Recurring payment processor when using clientside encryption (<a href="https://github.com/eileenmcnaughton/CiviCRM-eWay-recurring-payment-processor/tree/client-side-encryption-2" rel="nofollow">Github branch</a>), the CC value is submitted as a long encrypted string. CiviCRM renders this as a thousand stars on the confirm template; I wanted to render this nineteen stars rather than a thousand stars followed by the last four digits of the encrypted string.</p>
  
  <p>I was able to <a href="https://github.com/eileenmcnaughton/CiviCRM-eWay-recurring-payment-processor/commit/199479dd4c5aa7ec98e78609d16b08f71ad6d04a" rel="nofollow">achieve this with template overrides in the extension</a> (<a href="https://github.com/eileenmcnaughton/CiviCRM-eWay-recurring-payment-processor/pull/11" rel="nofollow">PR #11</a>), but it doesn't feel like the best approach to do this - much chance of conflict with other customisations / extensions / CiviCRM changes being my concern.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-21T22:12:56.350Z
Comments.Text: Just realised [`hook_civicrm_alterContent`](http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterContent) could be used to modify the output in this case (replace long strings of `*`s with a short string) ... this is probably as bad as the template route though, just differently bad :)
Comments.UserDisplayName: Chris Burgess
Tags: <extension><hooks><smarty>
Title: What hook(s) can modify variables passed into Smarty templates?
ThreadText: # What hook(s) can modify variables passed into Smarty templates?
  
  (Asked by: username_0 on 2015-10-21)
  
  Recently I needed to modify Smarty variables being passed into a template from an extension. I tried a couple of likely hooks, but neither of them seemed to provide this functionality. The templates in question were Confirm.tpl from various locations.
  
  Is there hook functionality (akin to Drupal's preprocess functions) which permits adjusting variables in templates?
  
  ---
  
  Background: for the eWay Recurring payment processor when using clientside encryption ([Github branch](https://github.com/eileenmcnaughton/CiviCRM-eWay-recurring-payment-processor/tree/client-side-encryption-2)), the CC value is submitted as a long encrypted string. CiviCRM renders this as a thousand stars on the confirm template; I wanted to render this nineteen stars rather than a thousand stars followed by the last four digits of the encrypted string.
  
  I was able to [achieve this with template overrides in the extension](https://github.com/eileenmcnaughton/CiviCRM-eWay-recurring-payment-processor/commit/199479dd4c5aa7ec98e78609d16b08f71ad6d04a) ([PR #11](https://github.com/eileenmcnaughton/CiviCRM-eWay-recurring-payment-processor/pull/11)), but it doesn't feel like the best approach to do this - much chance of conflict with other customisations / extensions / CiviCRM changes being my concern.
  
  **Tags:** extension, hooks, smarty
  
  > **Comments:**
  > **username_0**: Just realised [`hook_civicrm_alterContent`](http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterContent) could be used to modify the output in this case (replace long strings of `*`s with a short string) ... this is probably as bad as the template route though, just differently bad :)  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-10-22. Score: 1
  
  I often use the buildForm hook to modify data that is then passed to Smarty, or even add my own Smarty variables to the form.
  
  > **Comments:**
  > **username_0**: I'll have to try that again, I could see the variables in Smarty but directly modifying them in the form didn't affect the output. If it's not something specific to that tpl, I might need to brush up on my QuickForm :)  
  
  ---
  
  ### Answer by username_2 on 2017-04-18. Score: 0
  
  Just adding an example to the solution of Erik Hommel. It removes a create activity link
  function <>_civicrm_buildForm($formName, &$form) {
  
    if($formName == 'CRM_Activity_Form_ActivityLinks') { 
       $activityTypes = $form->get_template_vars('activityTypes');
       $ActityToRemoveKey = array_search('ActityToRemove', $activityTypes);
       if(isset($ActityToRemoveKey )){
       unset($activityTypes[$claimKey]);
       }
       $form->assign('activityTypes',$activityTypes);
    }
  }
  
  
  ---
  
  