Thursday, September 22, 2011

Theming blocks individually, by region, or by module

Designers can create multiple tpl.php files for blocks based on the specific block, the module that created the block, or the region that the block appears in.
Template files are searched in the following order:
block-[module]-[delta].tpl.php
block-[module].tpl.php
block-[region].tpl.php
block.tpl.php
For example, the user login block has a delta of '0'. If you put it in the left sidebar, when it's rendered, PHPTemplate will search for the following templates in descending order:
block-user-0.tpl.php
block-user.tpl.php
block-left.tpl.php
block.tpl.php
You can find the block's module and delta by looking at the html source of a page: each block's main DIV has the following classes and IDs:
<div class="block block-{module}" id="block-{module}-{delta}">
Note that custom blocks created in the admin UI count as coming block.module, so their template is 'block-block-[delta]'.

No comments:

Post a Comment