Nodes support node-$nodetype.tpl.php. Now, pages support page-$arg1-$arg2.tpl.php as well.

This patch allows themers to create different box templates for individual blocks based on modulename and delta. In addition, it allows themers to create a different box template for each region if desired.

for example:

block.tpl.php, block-poll.tpl.php, block-menu-3.tpl.php
box.tpl.php, box-footer.tpl.php and so on.

Same mechanism as existing node and page template suggestions.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Bèr Kessels’s picture

A big +1 from me. The code is simple the result is massive. This patch would make the most objects in our drupal pages behave consistent and allow very finegrained designs!

eaton’s picture

Title: PHPTemplate: Allow different templates for different blocks and boxes » PHPTemplate: Allow different templates for different blocks
FileSize
869 bytes

Here's a smaller version of the patch that only affects blocks. theme_box is used infrequently enough that it's not worth the change, and only adds more complexity to that. Via the _phptemplate_variables() hook, those who need to can still change them.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

tested and code reviewed. great improvement. eaton is on FIRE

beginner’s picture

Would this be documented anywhere?

moshe weitzman’s picture

of course it would - http://drupal.org/phptemplate is the place ... that whole section needs some love, folks.

eaton’s picture

FileSize
949 bytes

Yes, if committed this would go into the PHPTemplate docs.

I've added one last minute change. Since $block->region is available to us at this point, there's no reason not to include it. The patch will cause PHPTemplate to look for template files in the following order of preference:

block-$module-$delta.tpl.php
block-$module.tpl.php
block-$region.tpl.php
block.tpl.php

Dries’s picture

IMO, this should also be documented in the PHPdoc code. Similarly, we should document the page suggestion/discovery trial.

eaton’s picture

FileSize
2.19 KB

I've updated the PHPDoc comments for both phptemplate_page and phptemplate_block to note the new suggestion arrays that are generated. There's also an inline comment in the phptemplate_page function that explains the nature of the specific suggestions that are generated by default.

Dries’s picture

Looks good but I'd like to see this benchmarked first. On pages with several blocks, this might have a performance impact?

eaton’s picture

I just loaded a clean copy of head and enabled about a dozen blocks. Since the check happens regardless of what content the blocks contain, there's no need to worry about *which* ones are being used. Here are the numbers from my shared hosting server, over three runs of 1000 requests each:

Before Patch: 290.878, 255.064, 278.809 [ms] (mean)
After Patch: 261.917, 259.052, 261.717 [ms] (mean)

There's some variation from run to run, but it appears that the patch's impact is negligable.

It's also worth noting that both the page-template recommendation and block-template recommendation can be disabled by replacing $variables['suggestions'] in template.php with a single-element array containing JUST the file that should be search for.

drumm’s picture

Status: Reviewed & tested by the community » Fixed

Benchmarks look okay, so committed to HEAD, with editing for commenting style.

This needs to be documented in the handbook on Drupal.org.

Anonymous’s picture

Status: Fixed » Closed (fixed)
effulgentsia’s picture

Version: x.y.z » 5.0-beta1

Since $block->region is available to us at this point, there's no reason not to include it.

For Drupal 8, there's a reason to not include it anymore. If anyone here objects to that, please speak up in #1968360: Remove per-region block markup.