By minghui.yu on
return array(
'clf_header' => array(
'template' => 'header',
'arguments' => array('node' => $node),
'path' => $path2,
),
...
In hook_theme, when returning, can I pass the current loaded node object as $node?
Thanks,
(Above code does not work as expected. The passed $node is NULL not the current loaded node object)
Comments
hook_theme define theme
hook_theme define theme functions and the arguments they expect. While you can define static/fixed/default values, its up to the caller to passer in current values.
My Case
From page.tpl.php, I need to call a few other custom templates (like test.tpl.php). In those custom templates, I find the node object is not available. I have to either load the node object (get arg(1)) over and over across many custom template or I need a way to pass the node object to those templates.
arguments in theme hook
yes u can,
in your calling u can do this like this: -
print theme('key for hook',$nodeOBject);
---------------------------------------
and in hook_theme :---
return array(
'clf_header' => array(
'template' => 'header',
'arguments' => array('nodeobject' => null,'myname'=> 'i love drupal'),
'path' => $path2,
),
--------------
in your tpl file u can do this :-
print_r($nodeobject);//wiil print node object
print_r($nodeobject);// will print "i love drupal"