Blocks are the boxes visible in the side bars on the left- and right-hand side of the website. They are either exported by the engine or by any of the active modules. To really get your teeth into a drupal website, you are going to have to deal with blocks and administering blocks in a fairly sophisticated fashion. This means you will need to understand how the block placement strategy works.

The placement of blocks is delegated to the administrator. In most cases (i.e., the "custom" blocks), the user has complete control -- using preferences -- over whether or not they are enabled.

An administrator can lay out and arrange the available blocks to fit in two regions: "left" and "right". Regions simply contain blocks. In addition, an administrator can assign each block (within a region) a weight to sort them vertically. The heavier blocks will sink and the lighter blocks will be positioned nearer the top.

As mentioned, blocks may be arranged to fit in two regions: left and right. For theme builders, each region is identified by a corresponding constant: "left" and "right".

blocks"; } return $links ? $links : array(); } function block_admin_save($edit) { foreach ($edit as $key=>$value) { db_query("UPDATE blocks SET region = '". check_input($value[region]) ."', status = '". check_input($value[status]) ."', weight = '". check_input($value[weight]) ."' WHERE name = '". check_input($key) ."'"); } } function block_admin_display() { $result = db_query("SELECT * FROM blocks ORDER BY module"); // Generate output: $output .= "
\n"; $output .= "\n"; $output .= " \n"; while ($block = db_fetch_object($result)) { $module = module_hook($block->module, "admin") ? "module\">$block->module" : $block->module; $status .= "\n"; $weight .= "\n"; $region .= "\n"; $output .= " \n"; unset($status); unset($weight); unset($region); } $output .= "
blockmodulestatusweightregion
". $block->name ."$module$status$weight$region
\n"; $output .= "\n"; $output .= "
\n"; print $output; } function block_admin_preview() { $result = db_query("SELECT * FROM blocks WHERE status > 0 AND region = 0 ORDER BY weight"); $lblocks .= "\n"; while ($block = db_fetch_object($result)) $lblocks .= " \n"; $lblocks .= "
". ($block->status == 2 ? "$block->name" : $block->name) ."$block->weight
\n"; $result = db_query("SELECT * FROM blocks WHERE status > 0 AND region = 1 ORDER BY weight"); $rblocks .= "\n"; while ($block = db_fetch_object($result)) $rblocks .= " \n"; $rblocks .= "
". ($block->status == 2 ? "$block->name" : $block->name) ."$block->weight
\n"; $output .= "

layout scheme #1:

\n"; $output .= "\n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "
header
\n". ($lblocks ? $lblocks : " ") ." \n". ($rblocks ? $rblocks : " ") ."
footer
\n"; $result = db_query("SELECT * FROM blocks WHERE status > 0 ORDER BY weight"); $blocks .= "\n"; while ($block = db_fetch_object($result)) $blocks .= " \n"; $blocks .= "
". ($block->status == 2 ? "$block->name" : $block->name) ."$block->weight
\n"; $output .= "

layout scheme #2:

\n"; $output .= "\n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "
header
 \n". ($blocks ? $blocks : " ") ."
footer
\n"; $output .= "

layout scheme #3:

\n"; $output .= "\n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "
header
\n". ($blocks ? $blocks : " ") ." 
footer
\n"; print $output; } function block_init() { $result = db_query("SELECT * FROM modules"); while ($module = db_fetch_object($result)) { module_rehash($module->name); } foreach (module_list() as $name) { module_rehash($name); } } function block_admin() { global $op, $edit; if (user_access("administer blocks")) { print "configure | preview | help
\n"; block_init(); switch ($op) { case "help": block_help(); break; case "preview": block_admin_preview(); break; case "Save blocks": block_admin_save($edit); // fall through default: block_admin_display(); } } else { print message_access(); } } ?>