I found myself unable to theme nodeblocks in the way I expected and was outlined in the default tpl provided by the module.
Nodeblocks would not take me node-[type].tpl.php and I could'nt override the default template provided by the module...
I was able to properly theme and output nodeblocks as I expected by: (albeit without the use of the default tpl provided)
1) removing both theme functions from the module (nodeblock_theme() and nodeblock_preprocess_node())
2) By changing line 280 in the .module file to "$block['content'] = drupal_render(node_view($node, $settings['view_mode'], $lang));".
Have I misunderstood how the templates are supposed to work?
Or is there actually a bug here?
Comment | File | Size | Author |
---|---|---|---|
#6 | nodeblock-theme-hook-suggestions-1949192-6.patch | 1.55 KB | Ronino |
Comments
Comment #1
Johnny vd Laar CreditAttribution: Johnny vd Laar commentedThe order how (by default) tpl files are picked is:
So it seems like you forgot a "-" in your tpl name?
Comment #2
Johnny vd Laar CreditAttribution: Johnny vd Laar commentedoh for the record... the very very first template loaded is node--[nid].tpl.php
Comment #3
Johnny vd Laar CreditAttribution: Johnny vd Laar commentedOk I've found a bug. The template in the module folder was named node-nodeblock-default and in your theme you had to use node--nodeblock--default. I've fixed this and added a lot more template suggestions here:
http://drupalcode.org/project/nodeblock.git/commit/c64fb0e
so now there also is node--nodeblock, node--nodeblock--[content-type] and node--nodeblock--[nid].
Comment #4
weseze CreditAttribution: weseze commentedI'll try and have a look. Thanks for the feedback!
Comment #6
Ronino CreditAttribution: Ronino commentedThe problem with your implementation is that you are completely replacing existing theme hook suggestions that might have been added by other modules (besides Drupal's default ones node__[content-type] and node__[nid] which you are keeping in your replacement). For example, for me this breaks the layout as suggestions added by Panels are simply removed.
I attached a patch which fixes this by adding nodeblock's suggestions after node__[content-type] and node__[nid] and before any other custom suggestions.
By the way, is there any scenario where node--nodeblock--[content-type] and node--nodeblock--[nid] are needed? Aren't they the same as node--[content-type] and node--[nid]?
Comment #7
weseze CreditAttribution: weseze commentedI think that the nodeblock templates contain custom div wrappers. In theory it makes sense to have these templates. In practice I have never found myself using them.
Comment #8
Johnny vd Laar CreditAttribution: Johnny vd Laar commentedArray splice is a bit dangerous because other modules can change the array as well and now we might remove something we don't want.
Comment #9
Ronino CreditAttribution: Ronino commentedweseze wrote:
Well, I didn't mean the templates, but the theme hook suggestions. If you consider the built-in node--[nid] and blocknode's node--nodeblock--[nid], I don't see a need for the latter. A node with a specified nid can always be themed with node--[nid], so there seems to be no need for node--nodeblock--[nid]. The same holds true for node--[content-type] vs. node--nodeblock--[content-type]. As the nodeblock option is set for content types, node--nodeblock--block is not more specific than node--block, it just duplicates what is already possible, so I don't see any benefit.
Comment #10
Ronino CreditAttribution: Ronino commentedJohnny vd Laar wrote:
This is the referenced code:
This doesn't remove any array elements (as specified by the 0 length as the third parameter). nodeblock's theme hook suggestions are instead inserted between Drupal's two default ones node__[content-type] and node__[nid] and before other modules' custom ones. Removing elements indeed is the problem in the current version 1.3, where
$variables['theme_hook_suggestions'] = array(...)
just replaces anything that's there. That's why I created the patch...Comment #11
Ronino CreditAttribution: Ronino commentedComment #12
Johnny vd Laar CreditAttribution: Johnny vd Laar commentednode--nodeblock--[nid] and [content-type] could be useful if you use the same content type as block and as page and you want them to use different template files.
Comment #13
weseze CreditAttribution: weseze commentedJust tested this again and I still have 2 more problems/questions.
I created a node--[type].tpl in my custom theme but nodeblock ignored this template in favor of the default one provided by the module itself. To me this seems incorrect. A custom tpl should never be overriden by the one provided by the module, right?
And my second problem is that there really should be a block template as well. Or dit i miss it? Currently I find myself writing a condition in the main block.tpl to hide the block title if it is a nodeblock.
Comment #14
Johnny vd Laar CreditAttribution: Johnny vd Laar commentedI've committed the following change:
http://drupalcode.org/project/nodeblock.git/commitdiff/3c88968
I think this should fix all problems.
Comment #15.0
(not verified) CreditAttribution: commentedTypo