From a handbook comment:

I wonder if it would be possible to use a newly defined area (or any area of that matter) not in page.tpl.php but inside something like node.tpl.php, or comment.tpl.php or maybe even flexinode-x.tpl.php (x being the ID of the flexinode here of course).

At present this isn't possible. This line


  elseif ($hook == 'page') {

in _phptemplate_default_variables() ensures that the region variables are set only in full page rendering. This is probably a good thing, as blocks that display only in nodes would be confusing ('where's my block?' in non-node pages) and loading all blocks every time we themed a node (keeping mind that we might theme many nodes in a single page render) would be a lot of overhead.

But maybe we could look at something like assigning regions to different areas--some to pages, some to nodes.

function mytheme_regions() {
  return array(
    'page' => array(
      'floater' => t('floater'),
      'top_banner' => t('top banner'),
      'right' => t('right sidebar'),
      'content' => t('content'),
      'header' => t('header'),
      'footer' => t('footer')
    )
    'node' => array(
      'inline1' => t('inline 1'),
      'inline2' => t('inline 2'),
    )
  );
}

Then, on nodes, we would load any node-type regions.

Comments

zach harkey’s picture

+1 on this awesome idea.

nedjo’s picture

Title: Enable regions in nodes » How can you enable regions in nodes?
Category: feature » support

Well, on second thought, it looks like regions in nodes could be done at present with no PHPTemplate changes. I'm going to call this a support request until we see if this approach works.

Steps:

1. Define the regions you want in a template.php file, including some that will be used in nodes:


function mytheme_regions() {
  return array(
    'right' => t('right sidebar'),
    'content' => t('content'),
    'header' => t('header'),
    'footer' => t('footer')
    'inline1' => t('inline 1'),
    'inline2' => t('inline 2'),
  );
}

2. Load regions in a _variables hook.

In the same template.php file, load regions into nodes:


function mytheme_variables($hook, $vars) {
  $variables = array();
  if ($hook == 'node') {
    // Load region content assigned via blocks.
    foreach (array('inline1', 'inline2') as $region) {
      $variables[$region] = theme('blocks', $region);
    }
  }
  return $variables;
}

3. Output the regions in node.tpl.php (or individual node type templates) just as you would in page.tpl.php:

print $inline1;

These regions will still be loaded as variables in page calls, but won't be output if there is no code to output them in page.tpl.php.

Anyone want to give this a try and report back? (Note that the same approach should be applicable to assigning regions to any other page area that's the subject of a theme call.)

nedjo’s picture

Title: How can you enable regions in nodes? » Assign regions to specific themed areas: page, node, comment, etc.
Category: support » feature

This approach indeed works and we can indeed assign regions to any PHPTemplate template. I've updated the handbook documentation to give detailed instructions, http://drupal.org/node/29139. Use this rather than my draft code above, which had at least two errors ;)

I'd like to return to the approach I first suggested, of including template references in the _regions hook array. That might still be a useful enhancement. We would alter the

  elseif ($hook == 'page') {

section in _phptemplate_default_variables() to load blocks just for the called template (if it had any assigned regions). This small tweak would remove the need for custom _phptemplate_variables() handling, avoid unnecessarily loading all regions on page call (if some were for other templates), and also allow us UI cues to users as to where their regions will appear, e.g., in block configuration, tag regions with 'page', or 'node' (or 'content') as cues.

LAsan’s picture

Version: x.y.z » 7.x-dev

Any thoughts about this?

dvessel’s picture

Status: Active » Closed (works as designed)

A lot has changed in the theming system but it was possible to throw regions outside of "pages" and it still is now.