I'm trying to put a block in my node-story.tpl.php file. I've taken code from Regions in PHP Template and from Nick Lewis' blog but neither seem to work.

In my template.php I have

function  _phptemplate_variables($hook, $vars) {
    /* in this case, a hook refers to the beginning of tpl.php file
    Thus, case 'page' affects page.tpl.php. 'node' affects node.tpl.php, and case 'block' would affect
    block.tpl.php  */
    switch($hook) {
        case 'node' :
        if ($vars['page'] /* the equivolent of $page in node.tpl.php */ != 0) { 
            $vars['node_bottom']= theme_blocks('node_bottom');
        }
        break;
    }
    return $vars;
}

and in my node-story.tpl.php I have

<div id="node_bottom"> <?php print $node_bottom; ?> </div>

I know $node_bottom works; if I put it in page.tpl.php it prints. But it wont work within the node. and I've tried changing case "node': but to no avail.

Any ideas on how to get the block region in node-story.tpl.php?

~silverwing

Comments

styro’s picture

You should use theme('blocks', 'node_bottom') rather than theme_blocks('node_bottom') - that way your theme can still override theme_blocks() if it needs to.

The reason $node_bottom by default doesn't work in node templates is that region variables aren't defined for node templates, only for page templates. see:

http://api.drupal.org/api/function/_phptemplate_default_variables/5

for how the region variables get added to the page hook.

As for why your _phptemplate_variables() function isn't adding the variable properly, I'm not quite sure. The function looks OK from here. What happens if (just for testing/debugging at this stage) you remove the $vars['page'] check and set node_bottom anyway?

To isolate where the problem lies, try adding another arbitrary string variable to the node hook and see if that is set within node.tpl.php. If it does then your _phptemplates_variables() is set up right and the issue is with that particular region variable. If that doesn't work then there is some issue with the way you are adding variables to the node hook.

Another test: does it behave differently if you remove node-story.tpl.php and just try it in node.tpl.php?

--
Anton
New to Drupal? | Troubleshooting FAQ
Example knowledge base built with Drupal

silverwing’s picture

After watching the Simpsons tonight, I feel like I can honestly say...

D'oh!

I had a closing bracket } in the wrong place (from my region list.)

Thanks for taking the time to answer! I appreciate it! And I knew the answer shouldn't have been that hard!

~silverwing - grumblebrumble stupid closing bracket...grumblegrumble

___________________________
MisguidedThoughts | tvTonight

basicmagic.net’s picture

hi silverwing and thanks-

would you mind posting your revised complete code-
for any files you modified to achieve this (block in node-story.tpl.php)

would appreciate it greatly-
thanks

vincent, in buffalo

http://www.basicmagic.net
open source power for your enterprise

Drupal samurai for hire, based in Buffalo, New York, USA.
15+ years Drupal, 20+ years web.
http://basicmagic.net

silverwing’s picture

My template.php file has the following code

<?php

function MYTHEMENAME_regions() {
  return array(
       'right' => t('right sidebar'),
       'content_top' => t('content top'),
       'content_bottom' => t('content bottom'),
       'node_bottom' => t('node content bottom'),
       'footer' => t('footer')
  );}
function  _phptemplate_variables($hook, $vars) {
    /* in this case, a hook refers to the beginning of tpl.php file
    Thus, case 'page' affects page.tpl.php. 'node' affects node.tpl.php, and case 'block' would affect
    block.tpl.php  */
    switch($hook) {
        case 'node' :
        if ($vars['page'] /* the equivolent of $page in node.tpl.php */ != 0) { 
            $vars['node_bottom']= theme_blocks('node_bottom');
        }
        break;
    }
    return $vars;
}

And my node.tpl.php has

<div class="node_bottom"> <?php print $node_bottom; ?> </div>

___________________________
MisguidedThoughts | tvTonight

hectorplus’s picture

thanks for sharing it, it might come in handy for me sometime, when the needs come.

Tecito.com
The growing Hispanic community in Canada.

basicmagic.net’s picture

subscribe

Drupal samurai for hire, based in Buffalo, New York, USA.
15+ years Drupal, 20+ years web.
http://basicmagic.net

weedoo’s picture

suscribe

alexkb’s picture

Just to add to this, if you're trying to do the same thing in v6, check out Jacine's comments on this handbook page - its worked fine for me. Oh and don't forget to flush your theme registry when testing ;)

elliotttt’s picture

<?php
function  MYTHEME_preprocess(&$variables, $hook) {
    switch($hook) {
        case 'node' :
        if ($variables['page'] /* the equivolent of $page in node.tpl.php */ != 0) { 
            $variables['node_bottom']= theme_blocks('node_bottom');
        }
        break;
    }
    return $vars;
}
?>