regions

D6 regions, regions vs panels

有別於 Drupal 5 中在 template.php 定義region 的方式,
Drupal 6.x 的region 定義在 [theme].info 之內: (用Drupal 5.x 一篇的例子)

regions[left] = Left sidebar
regions[right] = Right sidebar
regions[content] = Content
regions[header] = Header
regions[footer] = Footer
regions[bottom_left] = Bottom left
regions[bottom_center] = Bottom center
regions[bottom_right] = Bottom right

regions[] array 之內用underscore, 右面可以用 space 空格

$bottom_right, $bottom_left, $bottom_center 等的變數就會出現在page*.tpl.php 之內
你可以將它們放到自定的位置, div 之內
//page.tpl.php

<?php
if ( $bottom_left || $bottom_center || $bottom_right || $feed_icons ):
endif;
?>

到 admin->site building->blocks 就會看到有'bottom left' 等等的選項了
ref: http://drupal.org/node/171224

而region vs panels 都是做很相似的工作,
便是提供一個分割頁面的方法
我的經驗是, 像我這個block, 每一頁的頁底都需要三個分割
用region 比較好
而特定的頁面的分割, 則使用panels 比較方便
而且, 要記得, regions 的variable 只會在 page*.tpl.php 中出現

使用regions 的要訣

在Druapl 中有關自定義regions,
使用panels 等等
有關將一個頁面分割為不同的部份,
以方便管理的技術, 這裡都有介紹過
但也因為有這兩種方法
我自己也一直想不通,
什麼時候使用panels, 什麼時候使用regions

後來, 為了效能的問題, >Read more

Regions

update2: Druapl 6.x regions
D6 update: Region 的定義在 .info 之內, 以下內容只適用於 D5 (2010-03-10)

新的模版有一個比較特別的地方,
就是自定了三個位於頁尾的regions,
而沒有使用panels.

當然, 第一是效能的考慮,
二來, 因為每一頁都會有這三個頁尾區
製作眾多panels 只費時失事

增加regions是theme 的管轄範圍
初初我也感到意外, 但為了保持彈性和可定製性
留在theme 的層面也是相當的合理
定製也只需要初階的編程能力
一般的模版開發者是可以應付得來的

在template.php 之內, 定義一個函數:

<?php
function mytheme_regions(){
  return array(
   
'right' => t('right sidebar'),
   
'content' => t('content'),
   
'header' => t('header'),
   
'footer' => t('footer'),
   
'bottom_left' => t('bottom left'),
   
'bottom_center' => t('bottom center'),
   
'bottom_right' => t('bottom right'),
  );
}
?>

mytheme 是這個theme的名字,
那樣, $bottom_right, $bottom_left, $bottom_center 等的變數就會出現在page.tpl.php 之內
你可以將它們放到自定的位置, div 之內
//page.tpl.php
<?php if ( $bottom_left || $bottom_center || $bottom_right || $feed_icons ):?>
......

到 admin->site building->blocks 就會看到有'bottom left' 等等的選項了