3

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), 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 (PR #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.

  • Just realised 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 :) – Chris Burgess Oct 21 '15 at 22:12
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.

  • 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 :) – Chris Burgess Oct 22 '15 at 6:54
0

Just adding an example to the solution of Erik Hommel. It removes a create activity link

function <<your extension>>_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);
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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