How do you display a page variable like $tabs in your node template? I',m trying to do this for advanced placement options. I tried doing it like this

template.php

function theme_preprocess_page(&$vars) {
if ($vars['node']->type == "nodetype"){
       $vars['template_files'][] = 'pagetemplate';
       $vars['node_tabs'][] = $tabs;
	}
     }

node template


print $node_tabs;

Obviously this didn't work. What am I doing wrong?

Comments

jan_v’s picture

Your are declaring $vars['node_tabs'][] as an array. You can't print an array.

try doing this:

print $node_tabs[0];

or you can scratch that if you change this:

function theme_preprocess_page(&$vars) {
if ($vars['node']->type == "nodetype"){
       $vars['template_files'][] = 'pagetemplate';
       //$vars['node_tabs'][] = $tabs; now you are saying that $vars['node_tabs'] is an array
       $vars['node_tabs'] = $tabs;
    }
     }
njguy’s picture

I tried what you said before and again, no luck.

njguy’s picture

I've tried literally everything i could think of, still nothing

I even tried this

$vars['node_tabs'] = array(&$tabs);
jan_v’s picture

variable $tabs isn't empty, right?

for debugging, try this:

function theme_preprocess_page(&$vars) {

   print_r($tabs);
   die();
}

You should get a white empty screen with the array value of $tabs shown.
if $tabs is empty, you'll get "array()" displayed.
if you get nada, your theme doesn't look in this function (make sure you replace theme_ by your theme name in function name)

InformaticsCentre’s picture

Hi all,

have you tried turning function theme_preprocess_page into function theme_preprocess_node

I know you can override blocks and regions in these preprocess functions, currently trying to get $tabs into the node-tpl files as we have different UIs depending on node-type. Tricky stuff

Dom

Dzhebarov’s picture

I managed to get the $tabs to the node.tpl.php like this:

First in the template.php add the following code

function theme_preprocess_node(&$vars) {
	if ($vars['node']->type == "nodetype"){
       $vars['template_files'][] = 'pagetemplate';
	   $vars['node']->tabs = theme('menu_local_tasks');
    }
}

This will add the tabs to your $node variables. Then in node.tpl.php you can access the tabs like this:

print_r($node->tabs);

Of course make sure to clear your cache after the changes :)