block.tpl.php

The block template in Adaptivetheme is a little different to most other themes. Instead of hard coding its markup Adaptivetheme generates most of it in adaptivetheme_process_block(), conditionally printing outer and inner wrappers. This is the same as how region templates work in Adpativetheme. This allows the core theme to have just one block template instead of five and eases code maintenance.

Adativetheme supplied variables

  • $outer_prefix: Holds a conditional element such as nav, section or div and includes the block id, classes and attributes.
  • $outer_suffix: Closing element.
  • $inner_prefix: Inner div with .block-inner and .clearfix classes.
  • $inner_suffix: Closing div.
  • $title: Holds the block->subject.
  • $content_processed: Pre-wrapped in div and attributes, but for some blocks these are stripped away, e.g. menu bar and main content.

The actual template is a little more verbose than region template, but you will recognize this as a pretty standard looking block template, just with the normal markup replace by variables:

<?php print $outer_prefix . $inner_prefix; ?>
  <?php print render($title_prefix); ?>
  <?php if ($title): ?>
    <h2<?php print $title_attributes; ?>><?php print $title; ?></h2>
  <?php endif; ?>
  <?php print render($title_suffix); ?>
  <?php print $content_processed; ?>
<?php print $inner_suffix . $outer_suffix; ?>

You can override this in your sub-theme with a normal block suggestion, i.e. use a standard block template if you prefer.

For example a typical navigation menu block template you might use this:

<nav id="<?php print $block_html_id; ?>" class="<?php print $classes; ?>"<?php print $attributes; ?>>
  <div class="block-inner clearfix">
    <?php print render($title_prefix); ?>
    <?php if ($block->subject): ?>
      <h2<?php print $title_attributes; ?>><?php print $block->subject; ?></h2>
    <?php endif; ?>
    <?php print render($title_suffix); ?>
    <div<?php print $content_attributes; ?>>
      <?php print $content ?>
    </div>
  </div>
</nav>

Or you can do similar things in themeName_process_block() by populating or stripping markup from the blocks as you desire. For example in AT Core we strip some markup for the Main Content block, because we just don't need these extra wrappers and it makes it easier to control the gutter margins:

<?php
 
// Strip outer and inner markup for block system main
 
if ($vars['block_html_id'] === 'block-system-main') {
   
$vars['outer_prefix'] = '';
   
$vars['outer_suffix'] = '';
   
$vars['inner_prefix'] = '';
   
$vars['inner_suffix'] = '';
   
$vars['content_processed'] = $vars['content'];
  }
?>

Additional menu bar block suggestions

Several new suggestions are provided to allow granular theming of menu bar blocks:

<?php
 
// Provide additional suggestions so the block__menu suggestion can be overridden easily
 
$vars['theme_hook_suggestions'][] = 'block__' . $vars['block']->region . '__' . $vars['block']->module;
 
$vars['theme_hook_suggestions'][] = 'block__' . $vars['block']->region . '__' . $vars['block']->delta;
?>

@see adaptivetheme_preprocess_block()
@see adaptivetheme_process_block()

Last updated 27th April, 2012 - 2:03pm