Quick Tool for Upgrading Custom Templates
Do you modify template files for your site? If so, you ought to know the tedious process of updating all the overridden template files every time you upgrade. (If you don't know that pain, either you've never upgraded or you should quit reading and go check your customized files.)
The method of using .extra.tpl files is helpful for tacking some jQuery on the end, but if you're altering parts of the page or adding to the middle, you've got to copy the whole template file and modify it.
At AGH Strategies, a number of clients have lots of customized templates, and when we run upgrades for them, we need a reliable and efficient way to separate the customizations from the rest of the file that's just copied from CiviCRM. We'll then apply the changes to new versions of the template files.
One command will take care of generating a diff of everything, but it's tricky to get all the inputs right, so I saved it as a bash script and shared it on GitHub so it's easy to modify for different types of installations. Here's the core of it:
diff -r -u yourcivicrmcodebase/templates yourcustomtemplatesdirectory | sed '/^Only in/d' > outputfile
It's basically a straightforward diff command, but the vast majority of template files won't have a corresponding custom template file. Using sed will prevent the output from being overwhelmed by the list of files that are only in the regular templates directory.
Once you generate the patch of your changes, you can apply it to the templates that come with the new version of CiviCRM.
The script will copy your custom templates to a temporary directory and overwrite them there with the corresponding templates from a new version of CiviCRM that you point it to. You can then try applying the patch of all your changes. Once all the changes are made, you can simply replace the contents of your custom templates folder with those in the temporary directory.
Let me know what you think in the comments, and please share any improvements or alternate approaches.