Hey,

I'm overwriting _phptemplate_links() for some customization.
I have to insert links that depend on the $node->nid but I cannot figure
out how to pass the $node into that function template, so I can
access $node->nid inside my template links.tpl.php.

Please can anyone give me a hint? :(

Thank you,
Christoph

Comments

nevets’s picture

If yes, you should probably look at hook_link and/or hook_link_alter. hook_link is used to add links to a node and sounds like what you are trying to do. The theme function applies to more than those links and does not necessarily apply to a node.

geme4472’s picture

If I understand you correctly, you could...

1) override your theme_links() function [phphtemplate_links()] and add a $nid = 0 argument (default it to zero so it doesn't screw up other uses of this function). Add code to make it do whatever you need it to depending on nid.

function phptemplate_links($links, $delimiter = '  ', $nid = 0) {
  if($nid){
    do_cool_stuff();
  } 
}

2) from the theme_node function, in the variable creation, call theme_links as:

'links'          => $node->links ? theme('links', $node->links, '  ', $node->nid) : '',

instead of

'links'          => $node->links ? theme('links', $node->links, '  ') : '',

Edit/Clarification: This is for overriding the theme_node() function, not for hacking the original. Just want to make sure no one is led astray.

solars’s picture

Both suggestions helped me a lot :)
Have to figure out whats best for my purpose, but thank you very much!

greetings,
Christoph

solars’s picture

okay, I tried that, I overwrote theme_node as mythemename_node() in template.php
and call the links function like this:

theme('links', $node->links, $node->nid)

with the custom links function:

function phptemplate_links($links = array(), $delimiter = ' | ',$nid=0) {
				return _phptemplate_callback('links', array('links' => $links, 'delimiter' => $delimiter ));
}

but in links.tpl.php $nid is empty...
whats wrong with that?

nevets’s picture

So you need to change

array('links' => $links, 'delimiter' => $delimiter )

to

array('links' => $links, 'delimiter' => $delimiter, 'nid' => $nid)
solars’s picture

ah right, I forgot that
but now $nid is always 0, the default value ..

nevets’s picture

So

theme('links', $node->links, $node->nid)

should be

theme('links', $node->links, '|', $node->nid)
solars’s picture

damn ...
thanks a lot :)

NiklasM’s picture

Hi, I need to do this in Drupal 6. Advice anyone?