I am a newbie at Drupal tweaking. I have copied Bartik theme into sites/all/themes and am modifying it as per our requirement.
One such requirement now is to programmatically modify the node title by appending value of some other field in the node to it before displaying the node. I have identified that the right way to achieve it is by updating the variables in hook_process_page()
or hook_preprocess_node()
function in template.php
file of the theme.
For testing purpose I have done the following change:
/**
* Override or insert variables into the page template.
*/
function MyThemeName_process_page(&$variables) {
// Raj: Experimenting
$vars['site_name'] = 'New title';
drupal_set_title('Test changed title');
echo "<script type=\"text/javascript\">alert('MyThemeName_process_page');</script>";
.
.
.
}
I could see that none of the changes are affected. Since I am just beginning to tweak, I have no idea how to debug a php function as it is a server side script. For the same reason I have tried to display alert which fails to display too!
I thought that the function is not being triggered at all, so I intentionally induced error in the 'echo' line by removing a character:
ech "<script type=\"text/javascript\">alert('MyThemeName_process_page');</script>";
The interpreter complains with this error:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /Applications/XAMPP/xamppfiles/htdocs/MyWebsite/cms/sites/all/themes/MyThemeName/template.php on line 48
This means that the interpreter is triggering the function, but why does not it echo and put out the alert?
Also, what is the approach to update the node title? I am assuming that there is some variable which I should be interested in the array "&$variables"
and conditionally update it, am I right?
Awaiting help!