Tag Archive: theme

Drupal theme variables

How to use Drupal theme variables?

Add the following codes into themplt.php

<?php
yourthemename_preprocess_page(&$variables) {
$variables['happyday'] = 'Happy ' . format_date(time(), 'custom', 'l') . '!';
}
?>
And display the variables in page.tpl.php:
<?php
print $happyday;
?>

Complex themes have many different block regions, some regions will only appear on certain pages or when viewing nodes of certain types. One very common use-case is to have both a page.tpl.php, and a page-front.tpl.php, each of which print out different regions.

How to define block regions in Drupal? Simply add a couple lines in your theme’s .info file:

regions[ad_top]        = Ad Top
regions[ad_bottom]     = Ad Bottom
regions[front_sidebar] = Front Sidebar
regions[sidebar_ad]    = Sidebar Ad
regions[content]       = Content
regions[feature_a]     = Feature A
regions[feature_b]     = Feature B
regions[feature_c]     = Feature C
regions[feature_d]     = Feature D

And then in your *.tpl.php file, wherever you want the region to appear, simply print out its machine-readable name.

<?php
print $feature_a;
?>
Setting the block’s visibility settings (on the block’s configuration form) to not show up on pages that do not have the region it’s assigned to printed. For example, setting any blocks assigned to the Feature A region to only show up on the <front> page.
Hiding the visibility of the block by some other means; for example, by limiting it to a role using the checkboxes on the block configuration form (or content types in Drupal 7), or installing a contributed module that implements hook_db_rewrite_sql() on the block list.
Block Page Visibility is used to set block visibility for each page. Or use Context module to control the render of blocks.