Specifically, I wish to redefine phptemplate_comment(). Is there a way I can do this within a theme folder without changing phptemplate.engine?

In the handbook, only overriding themes function not defined in phptemplate.engine is discussed.



I'd need to know the answer to this question myself. I need to be able to access the variables available to page.tpl from node.tpl, and so far the only way I've managed to do this is by hacking phptemplate.engine itself, but that's not at all ideal.
If anybody knows how to do this and could share, it'd be really appreciated.

Adrian answered my question a week or two ago here. http://ichris.ws/node/728 It might help you.

Thank you so much for pointing out that link to me! :D I successfully could take the hack out of phptemplate.engine.

Thanks again!

*I* didn't know about that little bit of brilliance, either, and had to do it a hacked way (include it in phptemplate.engine directly).

Chris, could you write up a book page (e.g. How to make additional variables available to your template files) here on Drupal.org? I'll approve it when you post.

I need to devote next week to my thesis, then I'll make sure I understand the solution and write it up. When it's done, I will let you know via the site contact. :)

I just ran into this same problem, and wanted to over-ride theme_links(), so when you write this up, there will be a lot of people who will praise you!

I am not too sure what you mean, "override the phptemplate_comment". You should just be able to just create the comment.tpl.php in your themes directory and then go to admin/themes and it should then start using it.

If you want to do something fancy if the phptemplate_comments doesn;t export the required information you can make use of the drupal api to get the required information.

Remember: After you add a file to your theme you need to go to admin > themes so that the cache of files will be rebuilt.
Gordon Heydon
Heydon Consulting

Gordon Heydon

I foresaw the need for modifying things like this .. so i created the _phptemplate_variables function.

A note: For these changes to take effect, you need to load the admin/themes page first.

function  _phptemplate_variables($hook, $vars) {
$hook) {
'comment' :
$vars['newvar'] = 'new variable';
$vars['title'] = 'new title';

The output of this function is merged with the variables returned from phptemplate_*, so you can easily adjust whichever variables you feel neccesary.

A neat trick is to count how many times each of the hooks is called, so you can pass an extra variable .. re :

function _phptemplate_variables($hook, $vars) {
$count = is_array($count) ? $count : array();
$count[$hook] = is_int($count[$hook]) ? $count[$hook] : 1;
$vars['zebra'] = ($count[$hook] % 2) ?'odd' : 'odd';
$vars['seqid'] = $count[$hook]++;

That is 'even' if it is an even number, and 'odd' if it is odd. This means you do zebra striping (ie: alternating colours) for each of your nodes / blocks / comments / whatever.

Then you can set up a some styles for class='$zebra' , which handle the alternating colours.

By using the sequential id in your template, you could choose wether or not to display certain parts of the nodes after the first 3 on the front page (You would probably have to check $is_front aswell.).

The future is so Bryght, I have to wear shades.

Adrian, this is really useful stuff -- please update this page: http://drupal.org/node/16383

The future is so Bryght, I have to wear shades.

Thanks a lot. this works great...

A small correction in the code :

$vars['zebra'] = ($count[$hook] % 2) ?'odd' : 'odd';

should be :

$vars['zebra'] = ($count[$hook] % 2) ?'odd' : 'even';


For example, I don't like the default submitted byline. I've tried implementing the _phptemplate_variables and cleared the site's cache by visiting admin/themes but I have yet to be successful in overriding $submitted.

That means I still have to hack up phptemplate.engine :(

edit: I'm probably just doing some wrong, because your example shows $title being overrided.

edit #2: OK, actually the problem is that the $node doesn't get passed around. So that was a bug in my code *BUT* it also seems like _phptemplate_variables *should* get passed the $node. I'm gonna hack up the callback to do that.

edit #3: Right - I'm a newb. No hacking up of the files needed as phptemplate_node adds a copy of the $node to $vars.