Skip to content

Custom templates and PHP files

Custom templates

  1. Create a folder, for example, drupal/sites/all/civicrm_templates. Add its full system path to the custom templates section on the directories page.
  2. To modify a template, copy its path and file into your custom templates directory. For example, copy civicrm/templates/CRM/History/Selector/Activity.tpl to drupal/sites/all/civicrm_templates/CRM/History/Selector/Activity.tpl. You can then modify the custom template.

CiviCRM searches your custom template directory and uses a template it finds there instead of the stock template. Your custom templates will not be overwritten when you upgrade CiviCRM.

Add Custom JavaScript Functions to Templates

As of version 3.4.3 / 4.0.3 CiviCRM will also check your Custom Templates Directories for files to append to a given template. These "extra" files should be named using the root template file name + 'extra.tpl'. For example, if you want to append some jQuery logic (or crmAPI calls, or ....) to the CiviEvent Dashboard - add them to this file in your custom templates directory tree: CRM/Event/Page/Dashboard.extra.tpl.

Note that you will need to start your "extra" custom file with the Smarty {literal} tag and then use {/literal} if you need to use any Smarty code or variables.

Case configuration files

If you are using the CiviCase component, your Case configuration files should also be stored under your custom templates path so they are not affected by upgrades. These should be placed in /CRM/Case/xml/configuration.

Custom PHP files

These are similar to custom templates in theory to php files that sit in this directory will over-ride the php files in the main CiviCRM fileset. They will not be overwritten when an upgrade takes place (which keeps your changes but can cause problems if the file has been upgraded and you don't port the changes across to your customised file).