Hello everyone!
This is my first post to the group, so I apologize in advance if I'm going about this the wrong way, and if so, do let me know how to do better next time.
The issue is I have a template I want a certain page to use, however, I'd like to have more variables than the ones that are pre-defined for the page template. For example, I'd like to have $name (='Harry'), $job_title (='Accounts'), and the $content(='Harry's done awesome work for us ever since...') variables accessible to the page-employees.tpl.php template file.
However, every time I try to pass something more complicated than a simple string into the $content variable, trouble. And there seems to be no way the template file recognizes any other than the default variables of the 'page' template.
I'm wondering if there's a way to go about it other than the following ideas below:
1) In the template using PHP code, tokenize some delimited string of information.
2) Write a separate template kind in the template engine that knows what to do with extra variables.
3) Selectively upgrade to Drupal 6 to be able to use something like this cool preprocessing engine I hear about.
Thanks for reading, and would greatly appreciate any feedback!
Best,
Hassan
Comments
PHP Template Variables
Oddly enough, you were pretty close. There's a function in D5 that you can use to set variables selectively within a page (the page variables, not the node type) or within selected node types- _phptemplate_variabes{}. It should look something like this:
function _phptemplate_variables($hook, $vars = array()) {switch($hook) {
case 'page':
$vars['my_variable'] = 'my variable';
case 'node':
$vars['my_node_variable'] = 'my node variable';
}
}
This is going to get complicated quickly, but that's how you do that in d5.
Thanks very much for the
Thanks very much for the help! What I ended up doing was writing a new theme function in template.php that used the _phptemplate_callback method, which brute forces the variables in there. Messy, and your solution's much cleaner, so that's the one I'll try when I have this problem again.
Thanks very much once again!
- Hassan