Intercepting and Overriding Variables

You can intercept and override the system's existing variables. Intercepting a variable is no different in practice from intercepting a themeable function: you simply restate it in the template. php file and make your modifications there, leaving the original code in the core intact. In this fashion, you are able to maintain your modifications inside the theme directory, rather than by modifying the core files.

I rltX The basic principles behind intercepts and overrides are discussed at I

I length in Chapter 4. I

To intercept an existing variable and override it with your new variable, you need to use the function _phptemplate_variables (), which is added to the template . php file with the following syntax:

<?php function _phptemplate_variables($hook, $vars = array()) { switch ($hook) {

return $vars;

Let's take an example and apply this. Assume you wish to substitute a new value for $title in page .tpl. php. To accomplish this task, add the following code to the template . php file:

<?php function _phptemplate_variables($hook, $vars = arrayO) { switch ($hook) { case 'page' :

return $vars;

With this change made and the file saved to your theme, the string "override title"

will appear, substituted for the original $title value. Note that the function specifies 1 page 1 ; this points our function to the page theme hook.

Was this article helpful?

0 0

Post a comment