Now it's easier to add custom behaviors to templates

2011-06-24 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.