Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
theme system
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
8 Apr 2011 at 06:02 UTC
Updated:
22 Apr 2011 at 23:11 UTC
Jump to comment: Most recent file
Comments
Comment #1
pillarsdotnet commentedExample code demonstrates the problem in both d6 and d7. Steps to reproduce:
Comment #2
pillarsdotnet commentedEDIT: now working, thanks to effulgentsia!
D7 version:
Comment #3
pillarsdotnet commentedComment #4
pillarsdotnet commentedEDIT: now working, thanks to effulgentsia!
D6 version:
Comment #5
ralt commentedHello,
I think you're using your preprocess function the wrong way.
When you do this :
You're "creating" a variable named $theme_hook_suggestions, which will be filled with 'a_b'. This means that if you display $theme_hook_suggestions in a.tpl.php OR a-b.tpl.php, you will see the string 'a_b'.
If you want to display $b in a-b.tpl.php ONLY, then you need to create the function
template_preprocess_a_b(&$v).If you use this :
Then the variable $b will be available in BOTH a.tpl.php and a-b.tpl.php.
I hope I'm making myself clear!
Edit : I'm only talking about D6 version. But D7 shouldn't be very different.
Comment #6
pillarsdotnet commented@Ralt -- Sorry. In the d6 version I should have had
template_filesinstead oftheme_hook_suggestions. Will re-edit above to correct. (Testing... corrected, but the problem persists; sigh.)From the d6
theme()docs:From the d7
theme()docs:You are suggesting that I should:
template_preprocess_a_b()instead of adding'a_b'totemplate_files.template_preprocess_a__b()instead of adding'a__b'totemplate_files.If that were so, then the d6
node.modulewould need to declare every possibletemplate_preprocess_node_$nid()in order for node-specific templates likenode-1.tpl.phpto be invoked.Comment #7
pillarsdotnet commentedupdated example code. Corrected "theme_template_suggestions" to "template files" in the d6 version but the problem persists.
Comment #8
pillarsdotnet commentedComment #9
meba commentedWhy is this a bug report?
Comment #10
pillarsdotnet commented@meba -- When an example as trivial as this doesn't work despite exactly following the instructions in the docs, that's a bug. Dunno if it's a docs bug or a core bug. Do you?
Comment #11
pillarsdotnet commentedComment #12
effulgentsia commentedSee http://api.drupal.org/api/drupal/modules--poll--poll.module/function/pol....
The problem is that the theme system only auto-discovers suggestions (or any templates) within themes. It does not auto-discover templates in modules. Modules need to declare them in hook_theme(), as in the poll.module example.
Comment #13
pillarsdotnet commentedThanks.
Comment #14
pillarsdotnet commentedSo the mechanism that makes
node--1.tpl.phpwork doesn't have anything to do with the code intemplate_preprocess_node()? Or does it need to be supported in both theme and module in order to work?Comment #15
bfroehle commentedI think what @effulgentsia was trying to say is that a--b.tpl.php will work if placed in your theme directory, but not in the module directory.
Comment #16
pillarsdotnet commentedOkay; I've got a working example I can build from now; thanks.
Soon as I've solved the immediate problem I'll work on building a docs page.
Comment #17
effulgentsia commentedThere's two parts to the equation for making suggestions work:
1. The theme registry needs to be aware that the suggestion is implemented (and where the implementation is).
2. A preprocess function needs to instruct the theme system which suggestions to search through.
So, template_preprocess_node() contains
$variables['theme_hook_suggestions'][] = 'node__' . $node->nid;, satisfying #2.For #1, the "--" delimiter is useful, because if node_theme() defines an entry for 'node', then if a theme contains
node--1.tpl.php, the theme system automatically finds it when it builds the theme registry. It doesn't do this automatically for any other delimiter.There is no auto-discovery of templates in modules, though. But, it's also much less common for modules to implement templates for suggestions. I don't think it happens anywhere in core other than poll.module. The main usefulness of suggestions is for greater control by the theme. In other words, there's lots of reasons why a site's custom theme would implement a node--1.tpl.php template, but why would a module do so?
Comment #18
pillarsdotnet commentedIn my particular case, I want to add a
htmlmail--simplenews.tpl.phpsuggestion template to HTML Mail in order to demonstrate how to customize Simplenews messages. My first attempt failed, and after a couple of hours of reading docs and re-writing code, I created a minimal problem demonstration module, and posted it here.