Page Templates
!!! warning The content in this page was written at some unknown time prior to 2013. It needs updating and may contain inaccuracies.
CiviCRM uses page template files to display all the pages. This makes it possible for a person to customize any CiviCRM screen to suit a special requirement or preference. The HTML for CiviCRM pages is not embedded in PHP code, instead a template engine (Smarty) sends the correct page to the web browser.
You should be familiar with HTML and CSS syntax to be comfortable editing page templates. Some page templates additionally make use of JavaScript and an Ajax utility, JQuery.
Changing page templates is the wrong choice when ...
- it is possible to make the needed changes by updating the CSS styles. For example, if a requirement is to hide or move some information or form fields on a screen, a CSS style for that HTML element can be changed to display: none, or position: absolute within the CSS file.
- there is a CiviCRM hook available that can control the page. For example, there is a hook that can modify the information on the Contact Summary screen
- there is no process in place to update the page templates after an upgrade to a new version of CiviCRM. Page templates are stored in a separate folder and are not touched during an upgrade, However new versions of CiviCRM often change which placeholder elements are available in various templates. Proper source control procedures are needed to simplify upgrades to new versions.
Smarty templates introduction
CiviCRM uses a page template engine called Smarty. This documentation
is focused on how Smarty is used within the CiviCRM environment. Every
Smarty element is enclosed between braces like these: {}
. All the
other text is going to be displayed directly as HTML in the rendered
page.
Each page template is stored in a file with the extension .tpl
. The
PHP code assigns variables for content that needs to be displayed, and
then lets the template engine take care of presenting it.
The Smarty template engine always does this process :