Published
Friday, June 24, 2011 - 18:01
Written by

For all you "customizers" out there - I wanted to highlight a cool new feature that is available as of the 3.4.3 / 4.0.3 release. You can now append jQuery functions, Smarty code, HTML (really anything) to any template without having to create a customized copy of the entire file. Wow - you say, "how the h?!# do I do that?"

All you need to do is put your "extra stuff" in a new file and save it as template_to_append_to.extra.tpl.

EXAMPLE: You want to add some jQuery to hide a few of the fields in the Contact Edit form - Contact.tpl.
1. Configure your Custom Templates directory
2. Create the directory structure in your custom templates directory (CRM/Contact/Form)
3. Write your jQuery script and save it in a file called Contact.extra.tpl

Voila - your jQuery script will be appended to the standard Contact.tpl template!

One heads up … if your file contains Javascript (as it probably will), you will need to start your "extra" custom file with the Smarty {literal} tag and the <script> tag. Then use {/literal}{$variable}{literal} if you need to use any Smarty code or variables. Finally, end the file with </script>{/literal}.

For customizations where you just need to add a script, this approach should save a lot of work during upgrades as you won't need to compare your customized copy to the latest and merge changes.

Comments

Was there any performance regression testing done on this?  I would expect a sizable impact unless CiviCRM has a template registry system like Drupal does. 

Hi,

 

Why are you expecting adding a simple file seeking+including having a big impact ? Don't recall having seen anything about smarty struggling with it.

 

disclaimer: haven't tested, but if you have experience on benchmarking performance, that would be very useful indeed.

Thanks, this makes it easier to include jQuery code than ever, without altering the original .tpl file.

Just used this for the first time -- fantastic new feature!