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.
If create menu block for example with name "test" and try to theming it, with file name block--menu--menu-test.tpl.php nothing happens. I mean specifically menu block theming not work.
Comment | File | Size | Author |
---|---|---|---|
#45 | 1021270-block-suggestions-45.patch | 851 bytes | larowlan |
#34 | 992376-34_block_suggestions.patch | 3.39 KB | wojtha |
#10 | issue-992376.patch | 1.58 KB | larowlan |
#6 | issue-992376.patch | 1.59 KB | larowlan |
#4 | issue-992376.patch | 1.63 KB | larowlan |
Comments
Comment #1
mdupontConfirmed. Custom menus will have a delta beggining with "menu-" (with a hyphen).
Due to this hyphen and the fact that the theme layer switches several times hyphens and underscores, the theme layer can't use the custom template. May be somewhat similar to #992376: Paths containing a hyphen aren't compatible with page theme_hook_suggestions.
After looking at includes/theme.inc and drupal_find_theme_templates() in particular, it appears that if we create a menu named "test" and a template named block--menu--menu-test.tpl.php, the theme layer will look for a block created by the menu module and with a delta of "menu_test" (block__menu__menu_test), whereas the menu block can effectively be found at block__menu__menu-test (notice the hyphen instead of the underscore). Therefore, the custom template isn't used. Embarrassing.
Comment #2
mdupontRequalifying the issue for better description. Can a Drupal guru confirm if this is a serious DrupalWTF?
Comment #3
larowlanSubscribe
Comment #4
larowlanHere's a patch for review
Comment #5
jhodgdonCan I suggest a different wording comment/doc portion of this patch, and also (a) don't use @see and (b) always put () after function names? My suggested doc:
Hyphens and underscores play a special role in theme suggestions. Basically, theme suggestions should only contain underscores, because within drupal_find_theme_templates(), underscores are converted to hyphens to match template file names, and then converted back to hyphens to match pre-processing and other function names. So if your theme suggestion contains a hyphen, it will end up as an underscore after this conversion, and your function names won't be recognized. So, we need to convert hyphens to underscores in block deltas for the theme suggestions.
And should we document this general rule somewhere else as well?
Comment #6
larowlanHere it is again with Jennifer's comment
I think this should go in the converting drupal 6.x modules to 7.x doco.
Coder_upgrade can also test for this too.
Marking this as needs test too, we should be able to test for these as with the page one #992376: Paths containing a hyphen aren't compatible with page theme_hook_suggestions
Comment #7
markabur CreditAttribution: markabur commentedThis should use strtr() -- see @sun's comment #2 here (similar issue): #890884: Targeted overrides for theme_menu_link() and theme_menu_tree() fail for menus with a hyphen
Comment #8
catchAlso, nitpicking but can we remove "Basically, " from the second sentence, it's not necessary there.
Comment #9
vitok-dupe CreditAttribution: vitok-dupe commentedpatch from #6 works, thx!
Comment #10
larowlanAnd again with feedback from comments 7 and 8
Comment #11
jhodgdon+1 on the doc portion of the patch anyway.
Regarding documenting this on the 6/7 module upgrade page, we already had:
http://drupal.org/update/modules/6/7#theme_hook_suggestions_1
http://drupal.org/update/modules/6/7#theme_hook_suggestions_2
I added an extra note similar to what's in this patch to the second section about the importance of using no hyphens in the pattern.
I also filed #1025528: Need documentation for the theme process/preprocess functions as a follow-up issue, because we need to have this documented on api.drupal.org as well, I think, and there's currently no place to document it.
Comment #12
markabur CreditAttribution: markabur commented#10 looks good, thanks.
Comment #13
pixeliteHave the same issue with "block--menu--primary-links.tpl.php".
This has nothing to do with menus, so perhaps the title of the issue should be "Blocks theme_hook_suggestions fails to clean-out dashes".
Comment #14
webchickLet's add a test for this, so we don't break it again.
Comment #15
vitok-dupe CreditAttribution: vitok-dupe commentedExcuse me, I maybe wrong to post it here but anyway. If in core D7 exist body_classes and other good stuff for theming, why not include page__type_..._.tpl.php templates? Now if need to theming pages specifically node type need to create mythemename__preprocess_page function with 2 line code in template.php:
why don't include this in core?
Comment #16
vitok-dupe CreditAttribution: vitok-dupe commentedin core I think it's 1 line code in the theme.inc at the 2269 line.
Comment #17
webchickvitok, that sounds like it should be moved to a separate issue of its own. This issue is about fixing a bug specifically with custom menu block theming.
Comment #18
vitok-dupe CreditAttribution: vitok-dupe commentedwebchick: "vitok, that sounds like it should be moved to a separate issue of its own. This issue is about fixing a bug specifically with custom menu block theming."
Yes I know, I just think if you one of those people who have weight in drupal develop process, then I one of those people who gives you idea :)
Comment #19
devenderdagar CreditAttribution: devenderdagar commented#4: issue-992376.patch queued for re-testing.
Comment #20
DerekAhmedzai CreditAttribution: DerekAhmedzai commentedI had the same problem with block templates for views.
I couldn't get
block--views--view_name-block_name.tpl.php
or
block--views--view_name_block_name.tpl.php
to work.Applying the patch from #10 fixed the problem.
Comment #21
jhodgdonThe patch in #10 is apparently waiting for a test to be added, as per #14. Otherwise it is RTBC. The status got inadvertently changed by #19.
Comment #22
khiminrm CreditAttribution: khiminrm commentedThe patch from #10 fixed my problem with block--views--news_block_block_1.tpl.php.
Comment #24
star-szrSubscribing. Wasted half a day trying to figure out why I couldn't override a views block.
Comment #25
Bill Pair CreditAttribution: Bill Pair commentedSubscribed as well! Damn, Drupal 7 is hard to theme if you're not a veteran...
Comment #26
birdonwire CreditAttribution: birdonwire commentedhad the same problem and i don't know how to apply the patch
Comment #27
Jo_ CreditAttribution: Jo_ commentedSubscribing - can't override views block...
Comment #28
Steven.Pescador CreditAttribution: Steven.Pescador commentedApplied the patch from #10 and is now working for me...
Comment #29
wojtha CreditAttribution: wojtha commentedBumping to 8.x
Comment #30
larowlanshould this be 8.x or should it stay at 7.x because it's a bug?
Comment #31
wojtha CreditAttribution: wojtha commentedIt needs to be fixed in both D8 and D7, but in D8 first.
Comment #32
Jevedor CreditAttribution: Jevedor commented#10 fixes my problem in drupal 7. thanks for the patch
Comment #33
wojtha CreditAttribution: wojtha commented#10: issue-992376.patch queued for re-testing.
Comment #34
wojtha CreditAttribution: wojtha commentedAdding unit test.
Comment #35
larowlanLooks good to me, thanks wojtha
Comment #36
Jo_ CreditAttribution: Jo_ commented#10 fixed my issue. Thanks.
Comment #37
dcrocks CreditAttribution: dcrocks commentedRelated:
http://drupal.org/node/1129972
http://drupal.org/node/1076132
http://drupal.org/node/992376
Comment #38
pingers CreditAttribution: pingers commented+1 rtbc & backport it please.
Comment #39
404 CreditAttribution: 404 commentedran into similar problem. Hope this get resolved asap in d7. it's holding back the themers.
subscribe.
Comment #40
sledan CreditAttribution: sledan commentedHow do you add the patch given in post #10 ?
Comment #41
jeffschulerPatch in #34 works for me [though in D7].
Comment #42
webchickAwesome! Thanks for the test! It's really great to have coverage of these tricky theme details.
One question:
Should "back to hyphens" not be "back to underscores"? This is something that can be fixed during commit (though a fresh patch wouldn't hurt).
Comment #43
wojtha CreditAttribution: wojtha commentedUps. Just realized that Dries already commited it to Drupal 8. But with wrong description.
It seems that Dries unwillingly merged two commits in to the one and he apparently didn't notice...
Comment #44
webchickNice catch!
Committed this to 7.x (with the docs typo fix) in order to keep the two in sync. This needs to go back to 8.x just for that minor typo.
Comment #45
larowlanFixes typo as suggested
Comment #46
wojtha CreditAttribution: wojtha commentedShould be commited to both D7 and D8.
Comment #47
m4oliveiI ran into this issue with the aggregator module in core, which names its block delta's 'feed-1', 'feed-2', etc. I can confirm this resolves the issue on the latest 7.x-dev. Thanks!
Comment #48
catchtagging for backport.
Comment #49
larowlanPretty sure this is already in 7 - see 44
Comment #50
webchickCommitted and pushed to 8.x. Thanks!
Comment #52
waltf CreditAttribution: waltf commentedis this supposed to be fixed or not?
I'm using drupal 7.8 and block--system--main--menu.tpl.php doesn't work.
Do i still need to apply the patch?
Comment #53
jeffschulerwaltf:
block--system--main-menu.tpl.php
Only one hyphen in main-menu.
Comment #54
marvzz CreditAttribution: marvzz commentedEDIT: Seems working on 7.10 but I need to name my menu block templates with underscores instead of dash for the blocks delta.
So if i have a menu named menu-my-menu, its block template should be block--menu--menu_my_menu.tpl.php
Comment #55
bcreeves CreditAttribution: bcreeves commentedThis is not working for me with a menu I created that has a URL path of: menu-footer-menu-2
I created a block--menu--menu_footer_menu_2.tpl.php which didn't work. I also tried it with underscores as dashes.
I'm using Drupal v7.10
Do I need to apply the patch?
Comment #56
apadernoIf it needs to be back-ported to Drupal 7, then its status should be "needs work."
Comment #57
star-szrI believe the fix has been commited to 7.x (#44) and 8.x (#50), so this can be closed.
Comment #58
spencerthayer CreditAttribution: spencerthayer commentedThe patch is still needed with Drupal version 7.17. This issues IS NOT closed. Come on Drupal, WTF? Also the 1021270-block-suggestions-45.patch doesn't work for 7.17.
Comment #59
pingers CreditAttribution: pingers commentedThis is already in D7 (as committed in May 2011).
@spencerthayer please read [#73179], [#73178] & [#45111].
Comment #60
Elijah Lynn