I think this is possibly a bug. I'm trying to customise the way multiple cck fields are displayed as I need to emulate the Ubercart default display of images as described in this issue here http://drupal.org/node/763344. To do this I want to modify nd_cck.tpl.php, I have made the changes I require and when I save these into the module template folder /sites/all/modules/nd_contrib/nd_cck, everything works perfectly.

This is obviously not the right way to do it though but when I add the same nd_cck.tpl.php file to my sites theme folder no name I have tried as suggested by theme developer works to override the modules tpl file.

It was my understanding that DS, ND and NDC are meant to work with custom tpl's and that's why they have been included? Or am I doing something wrong?

CommentFileSizeAuthor
#4 nd_cck.module.patch397 bytesdenes.szabo
nd_ck_tpl.png17.37 KBRene Hostettler

Comments

swentel’s picture

Will probably be a bug indeed - got one a week ago or so for nd.module also - see #743872: Specific node type templates not rendering Ok. I'll look into that this weekend.

swentel’s picture

Status: Active » Fixed

Ok, due to a limitation of the theme registry, copying that file to your themes folder will only work if the base template (content-field.tpl.php) is also in the themes directory of your theme. So you can either:

a) copy content-field.tpl.php to our themes folder
b) paste the code from nd_cck into content-field.tpl.php and only put that file in your themes folder

With this bug, I discovered I have actually the same problem with all other modules and sadly enough can't get around it from code. I've reflected this in all the modules' documentation. Thanks for the report!

swentel’s picture

Status: Fixed » Closed (fixed)
denes.szabo’s picture

Status: Closed (fixed) » Needs review
StatusFileSize
new397 bytes

Sorry for reopen it, but I have the same problem, but, I think, I have the solution too.

So, I have the a field named 'field_fb_images'. The theme system generates these templates as suggestions in the cck/content.module's content_preprocess_content_field():

Array
(
    [0] => content-field
    [1] => content-field-field_fb_images
    [2] => content-field-feedback
    [3] => content-field-field_fb_images-feedback
    
)

The nd_cck module adds to this suggestions the 'nd_cck' in the nd_cck_preprocess_content_field() function by $variables['template_files'][] = 'nd_cck';

So the suggestions now are:

Array
(
    [0] => content-field
    [1] => content-field-field_fb_images
    [2] => content-field-feedback
    [3] => content-field-field_fb_images-feedback
    [4] => nd_cck
)

Then the theme always will use the nd_cck. No way to use any other template. As the theme system suggestion generate says: "The order is FILO, so this array is ordered from least appropriate first to most appropriate last."

The theme system will use the mytheme/nd_cck.tpl.php or nd_contrib/nd_cck/nd_cck.tpl.php.
The latest nd_cck/nd_cck.tpl.php always there, so the search for alternate templates will stopped. No way I use my custom content-field-field_fb_images-feedback.tpl.php.

But, the solution is: the $variables['template_files'][] = 'nd_cck'; must be replaced by array_unshift($variables['template_files'], 'nd_cck'); The nd_cck template suggestion must be placed the back seat (now to the first according to the FILO).

My template suggestion now are:

Array
(
    [0] => nd_cck
    [1] => content-field
    [2] => content-field-field_fb_images
    [3] => content-field-feedback
    [4] => content-field-field_fb_images-feedback
)

I think, this is the good behavior of template the suggestions. For now my theme uses content-field-field_fb_images-feedback.tpl.php as a most precisely tailored template for my field.

I attached my patch against the dev.

denes.szabo’s picture

Sorry I thought about it. With my solution the theme system never will use nd_cck.tpl.php if the cck module is enabled, because of the content-field.tpl.php always exists in the cck module...

jbizzay’s picture

Here's what I am doing as a quick fix. In my template.php file, adding a template suggestion for nd_cck files:

/**
 * Implementation of hook_preprocess_content_field().
 */
function themename_preprocess_content_field(&$vars) {
  $vars['template_files'][] = 'nd_cck-'. $vars['element']['#field_name'];
}

Now I can use nd_cck-field_article_image.tpl.php in my theme folder

swentel’s picture

Status: Needs review » Closed (fixed)

Ok, attached is a patch - committed to CVS - it uses the array_unshift and after that does a switch on the first and second key - a bit hackish, but it works :), so now the order looks like:

content-field
nd_cck
other-templatefiles

swentel’s picture

aargh, forgot the patch and deleted it already from my local system, here's the diff : http://drupalcode.org/viewvc/drupal/contributions/modules/nd_contrib/nd_...