Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When using the current system, it is not possible to using a correct template override.
I will post a patch that solves the problem.
Comment | File | Size | Author |
---|---|---|---|
#1 | 1100736.patch | 4.13 KB | joostvdl |
Comments
Comment #1
joostvdl CreditAttribution: joostvdl commentedPatch that should solve this issue.
Comment #2
RobW CreditAttribution: RobW commentedDidn'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.
Comment #3
joostvdl CreditAttribution: joostvdl commentedtemplate filename should be: file-collection-item--field-collection-name.tpl.php
(so use dashes instead of underscores!)
Comment #4
RobW CreditAttribution: RobW commentedAh, 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?
Comment #5
joostvdl CreditAttribution: joostvdl commentedYou can check ik wit the theme developer. This seems the correct way to name a template.
Comment #6
joostvdl CreditAttribution: joostvdl commentedCan this issue be tested by other so it can be put in head?
Comment #7
fago>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?
Comment #8
RobW CreditAttribution: RobW commentedJoostvdl 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.
Comment #9
WilliamB CreditAttribution: WilliamB commentedCan this be commited?
Seems like a solid patch and would help theming.
Comment #10
fagoI just renamed the file.
Comment #11
WilliamB CreditAttribution: WilliamB commentedBut 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!
Comment #12
fagoComment #14
mghatiya CreditAttribution: mghatiya commentedSo 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.
Comment #15
laceysanderson CreditAttribution: laceysanderson commentedSo 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.
Comment #16
tahiticlic CreditAttribution: tahiticlic commentedWell, 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?
Comment #17
tahiticlic CreditAttribution: tahiticlic commentedAnyone having the same troubles ?