When using the current system, it is not possible to using a correct template override.

I will post a patch that solves the problem.

CommentFileSizeAuthor
#1 1100736.patch4.13 KBjoostvdl
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joostvdl’s picture

Status: Active » Needs review
FileSize
4.13 KB

Patch that should solve this issue.

RobW’s picture

Didn't have any luck with this patch. Neither "field_collection_item--[field_collection name].tpl.php" or "field_collection_item--[field_collection uri].tpl.php" overrode "field_collection_item.tpl.php.

joostvdl’s picture

template filename should be: file-collection-item--field-collection-name.tpl.php

(so use dashes instead of underscores!)

RobW’s picture

Ah, thanks, works now.

Is this correct behavior though? The original .tpl included with the module is field_collection_item.tpl.php, and the unpatched and patched module both recognize it as a theme override. I would think it should be standardized as one or the other, right?

joostvdl’s picture

You can check ik wit the theme developer. This seems the correct way to name a template.

joostvdl’s picture

Can this issue be tested by other so it can be put in head?

fago’s picture

Title: Theming function is not working correct » Template filename should use dashes not underscores
Status: Needs review » Needs work

>Template filename should use dashes not underscores

Is that correct, even for single underscores? (I'm no themer.) If so, of course we should do so and follow that.

Anyway I think, it works as it is now too + as underscores are automatically converted for double underscores, I assume they are for single underscores too. So as #4 states, re-naming the file might be enough.

>+ 'pattern' => 'field_collection_item__',
Why should we need this line? Using __ as pattern is the default anyway?

RobW’s picture

Joostvdl is correct, all other modules I looked at use the dash instead of underscore. Field-collection-item.tpl.php has worked since the start of this issue, if I remember correctly -- the tpl included with the module should probably be renamed to it.

WilliamB’s picture

Can this be commited?
Seems like a solid patch and would help theming.

fago’s picture

I just renamed the file.

WilliamB’s picture

But did you change the pattern as well?

Btw Fago can you look into this issue:
I've a field collection called field_art_para.
This field contains 2 fields: field_para_img and field_para_txt.

I'm theming field_art_para using field--field_art_para.tpl.php.
But the problem is it affects also field_para_img and field_para_txt which somehow both uses this template.
And if i try to theme theme individualy via field--field_para_img.tpl.php or field--field_para_txt.tpl.php it just doesn't do anything.

I found a working around using a switch($element['#field_name']) in field--field_art_para.tpl.php but that ends up making a dirty template.

Also i want to thank you A LOT for this module without which i'd be in trouble to do what i wanted to do!

fago’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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

mghatiya’s picture

So what is the final verdict here? The patch mentioned above is being shown as "failed simple test". Other comments are mostly about what is not working.
Please let me know what is the right way of naming the theme file.

laceysanderson’s picture

So the final verdict seems to be that even though the patch failed testing this functionality has been implemented.

I just created a field-collection-item--[my-field-name].tpl.php in my theme and put a print_r(get_defined_vars()); in it to see what I had. It showed up on my node page and had a $content variable with the fields in my field collection in it! Now I can just theme as usual.

More detail:
I have a field collection called field_paint_colour (on admin/structure/field-collections) with the following sub-fields: field_brand, field_colour_name, field_barcode, field_colour_hex.

I created a file: field-collection-item--field-paint-colour.tpl.php in my theme directory. This is where you will define the output for your field collection.

All the sub-fields are found at $content[sub_field_name] (ie: $content['field_brand'] ) and can be rendered by adding print render($content[sub_field_name]); within valid HTML code in your field-collection-item--field-paint-colour.tpl.php file.

One thing to keep in mind -you need to clear your cache 2X to see any changes.

tahiticlic’s picture

Well, using the last dev version (7.x-1.0-beta4+4-dev), this doesn"t work.

I've a field collection named "field_prix". Then I've created a template file named field-collection-item--field-prix.tpl.php and cleared cache, nothing happens, the template file is not used. I've tried several variations of this template naming, but no way...

Is there something special to do?

tahiticlic’s picture

Anyone having the same troubles ?