Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#8 | block-tpl_1.patch | 2.19 KB | eaton |
#6 | block-tpl_0.patch | 949 bytes | eaton |
#2 | block-tpl.patch | 869 bytes | eaton |
block-and-box.patch | 1.24 KB | eaton | |
Comments
Comment #1
Bèr Kessels CreditAttribution: Bèr Kessels commentedA 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!
Comment #2
eaton CreditAttribution: eaton commentedHere'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.
Comment #3
moshe weitzman CreditAttribution: moshe weitzman commentedtested and code reviewed. great improvement. eaton is on FIRE
Comment #4
beginner CreditAttribution: beginner commentedWould this be documented anywhere?
Comment #5
moshe weitzman CreditAttribution: moshe weitzman commentedof course it would - http://drupal.org/phptemplate is the place ... that whole section needs some love, folks.
Comment #6
eaton CreditAttribution: eaton commentedYes, 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
Comment #7
Dries CreditAttribution: Dries commentedIMO, this should also be documented in the PHPdoc code. Similarly, we should document the page suggestion/discovery trial.
Comment #8
eaton CreditAttribution: eaton commentedI'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.
Comment #9
Dries CreditAttribution: Dries commentedLooks good but I'd like to see this benchmarked first. On pages with several blocks, this might have a performance impact?
Comment #10
eaton CreditAttribution: eaton commentedI 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.
Comment #11
drummBenchmarks look okay, so committed to HEAD, with editing for commenting style.
This needs to be documented in the handbook on Drupal.org.
Comment #12
(not verified) CreditAttribution: commentedComment #13
effulgentsia CreditAttribution: effulgentsia commentedFor 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.