1. To theme blocks on different regions by a simple file, the follwing code should be changed from

  function phptemplate_block($block) {
    return _phptemplate_callback('block', array('block' => $block));
  }

to

  function phptemplate_block($block) {
    return _phptemplate_callback('block', array('block' => $block), 'block-' . $block->region);
  }

Now you can e.g. theme blocks on the left sidebar with a "block-left.php".

2. Intoducing new block regions (that make sense):

Change

  function phptemplate_regions() {
    return array(
         'left' => t('left sidebar'),
         'right' => t('right sidebar'),
         'content' => t('content'),
         'header' => t('header'),
         'footer' => t('footer')
    );
  }

to

  function phptemplate_regions() {
    return array(
         'left' => t('left sidebar'),
         'right' => t('right sidebar'),
         'content-bottom' => t('content (bottom)'),
         'content-top' => t('content (top)'),
         'header' => t('header'),
         'footer' => t('footer')
    );
  }

Comments

adrian’s picture

Status: Needs review » Reviewed & tested by the community

a big +1 from me.

very good thing to do dude. =)

killes@www.drop.org’s picture

Status: Reviewed & tested by the community » Active

There is no patch.

dfg’s picture

StatusFileSize
new1.29 KB

patch encl.

dfg’s picture

Status: Active » Reviewed & tested by the community

lalala

dfg’s picture

Assigned: Unassigned » dfg

...

markus_petrux’s picture

Status: Reviewed & tested by the community » Closed (works as designed)

IMHO, the block-region thing is not needed. You can do something like this in your theme:

<?php
  switch ($block->region) :
    case 'header':
    case 'footer':
?>
<div class="block-<?php print $block->region; ?>"><?php print $block->content; ?></div>
<?php
      break;
    case 'content':
?>
<div class="box">
	<h3 class="title"><?php print $block->subject; ?></h3>
	<div class="content"><?php print $block->content; ?></div>
	<br class="clear" />
</div>
<br />
<?php
      break;
    default:
?>
<div class="block block-<?php print $block->module; ?>" id="block-<?php print $block->module; ?>-<?php print $block->delta; ?>">
	<h2 class="title"><?php print $block->subject; ?></h2>
	<div class="content"><?php print $block->content; ?></div>
	<br class="clear" />
</div>
<br />
<?php
      break;
  endswitch;
?>

...or you could do this including external files to your block.tpl.php script, or maybe differences between block regions can be styled using CSS with something like:

#sidebar-left .block {
  foo: blue;
}
#sidebar-right .block {
  bar: red;
}

Then, someone correct me if I'm wrong, but you could create a file in yourtheme folder named yourtheme.theme and include a function yourtheme_regions() to override the theme/system default.

PS: I would set the status as "not apply", but it doesn't exist, it seems "by design" may also work.

dfg’s picture

Status: Closed (works as designed) » Needs review

I don't understand your arguments. Hence this:

1. You are right, that you could switch all cases in the "block.php" template, but it does not hurt to change

  function phptemplate_block($block) {
    return _phptemplate_callback('block', array('block' => $block));
  }

to

  function phptemplate_block($block) {
    return _phptemplate_callback('block', array('block' => $block), 'block-' . $block->region);
  }

This just gives you the possibility to put the code for different block-regions in different files. And the old behaviour works as well. So why not changing this line?

2. Even if you _could_ introduce new regions with your own theme, I approach a consistent feature for all themes. Go on the "admin/block" page, try it with different phptemplate-themes - you will always see a dummy "content" block on the bottom. This behaves so, because the "content" block in appended to the bottom of the content in phptemplage.engine.

So this justifies calling this block "content-bottom", and introducing a "content-top", that is logically appended at the top of the content. This feature then is available in all phptemplate themes, and you can change the themes without being scared that your block vanishes.

markus_petrux’s picture

1) True, true, it sounds like a simple change that offers more power. ;-)

2) Those new 'content' regions are already be populated by the following code in _phptemplate_default_variables():

if (!in_array($region, array('left', 'right', 'footer'))) {
  isset($variables[$region]) ? $variables[$region] .= theme('blocks', $region) : $variables[$region] = theme('blocks', $region);
}

I have a doubt, would it be better to concatenate those block regions in page.tpl.php?

...or add 'content-top' and 'content-bottom' to that in_array check in _phptemplate_default_variables()?

dfg’s picture

StatusFileSize
new1.89 KB
markus_petrux’s picture

I have applied (manually, though) and worked like a charm.

There is something that might be addressed related to content-top blocks. Concatenated at the begining of $content, it shows blocks below other things that may come before the content, such as the title, tabs, help and messages.

Should content-top blocks be rendered before all that?

Crell’s picture

Just to throw a small wrench in here, should the regions not be called content-before and content-after rather than content-top and content-bottom? Top and bottom are visual layout issues that should be handled by CSS. Before and after define the order in the output, which is what is actually being changed here.

Otherwise, +1 on being able to put blocks on both "ends" of content.

dfg’s picture

There is something that might be addressed related to content-top blocks. Concatenated at the begining of $content, it shows blocks below other things that may come before the content, such as the title, tabs, help and messages.
Should content-top blocks be rendered before all that?

Maybe sometimes you want a "content-top" block below title/messages/tabs/help, sometimes before that, and sometimes inbetween. As you know, the only possibility that can be hardcoded in phptemplate.engine, is concatenating it before $content. But this also menas, that content-top ist below title/messages/tabs/help. Every other combination can only be done by introducing a new region within a theme (*), and placing a call somewhere else in the theme.

Just to throw a small wrench in here, should the regions not be called content-before and content-after rather than content-top and content-bottom? Top and bottom are visual layout issues that should be handled by CSS. Before and after define the order in the output, which is what is actually being changed here.

Anybody else wants "content-before" instead of "content-top", and "content-after" instead of "content-bottom"? I have no preference.

(*) Does anybody know how to inject new block regions within a phptemplate theme, without changing the core stuff?

markus_petrux’s picture

printing $content_top in page.tpl.php?

dfg’s picture

I mean declaring new block regions, so that you can select this region on admin/block.

markus_petrux’s picture

Do you mean this?

You can create a file named 'yourtheme.theme' that includes a function similar to this:

function yourtheme_regions() {
  return array(
       'left' => t('left sidebar'),
       'right' => t('right sidebar'),
       'header' => t('header'),
       'footer' => t('footer')
  );
}

This script, if exists in your theme folder, is included by init_theme() (in themes.inc) and you can use it override any other theme_whatever function.

dfg’s picture

Works. Thanks.

markus_petrux’s picture

That's why I believe one of your additions is not really needed. You can do this:

1) Create yourtheme.theme with the following contents:

function phpmix_org_regions() {
  return array(
       'left' => t('left sidebar'),
       'right' => t('right sidebar'),
       'content_top' => t('content (top)'),
       'content_bottom' => t('content (bottom)'),
       'header' => t('header'),
       'footer' => t('footer')
  );
}

2) In page.tpl.php (or whatever else .tpl.php file), add the following:

<?php print $content_top; ?>
<?php print $content_bottom; ?>

And you can place your regions wherever you wish.

Jaza’s picture

Version: x.y.z » 4.7.x-dev
Status: Needs review » Closed (fixed)

Closing. The region-specific block theming is implemented in Drupal 5. The extra content-top and content-bottom regions are not needed in core, IMO - themers can add them if they want them.