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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Johnny vd Laar’s picture

Status: Active » Postponed (maintainer needs more info)

The order how (by default) tpl files are picked is:

  1. node--[content-type].tpl.php in your theme
  2. node-nodeblock-default.tpl.php in your theme
  3. node-nodeblock-default.tpl.php in the nodeblock module

So it seems like you forgot a "-" in your tpl name?

Johnny vd Laar’s picture

oh for the record... the very very first template loaded is node--[nid].tpl.php

Johnny vd Laar’s picture

Status: Postponed (maintainer needs more info) » Fixed

Ok 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].

weseze’s picture

I'll try and have a look. Thanks for the feedback!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Ronino’s picture

Category: support » bug
Status: Closed (fixed) » Needs review
FileSize
1.55 KB

Ok 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].

The 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]?

weseze’s picture

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]?

I 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.

Johnny vd Laar’s picture

Array splice is a bit dangerous because other modules can change the array as well and now we might remove something we don't want.

Ronino’s picture

weseze wrote:

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]?

I 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.

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.

Ronino’s picture

Johnny vd Laar wrote:

Array splice is a bit dangerous because other modules can change the array as well and now we might remove something we don't want.

This is the referenced code:

array_splice($variables['theme_hook_suggestions'], 2, 0 , array(
  'node__nodeblock',
  'node__nodeblock__default',
  'node__nodeblock__' . $variables['node']->type,
  'node__nodeblock__' . $variables['node']->nid,
));

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...

Ronino’s picture

Johnny vd Laar’s picture

node--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.

weseze’s picture

Just 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.

Johnny vd Laar’s picture

Status: Needs review » Fixed

I've committed the following change:
http://drupalcode.org/project/nodeblock.git/commitdiff/3c88968

I think this should fix all problems.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Typo