Closed (duplicate)
Project:
Drupal core
Version:
8.0.x-dev
Component:
theme system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
8 Mar 2012 at 02:43 UTC
Updated:
22 Oct 2015 at 00:28 UTC
Jump to comment: Most recent
Comments
Comment #1
ankur commentedUsually, when you create a field named "image" through the field_ui module in core, your field would end up being named "field_image". So your template file should be named
field--field_image.tpl.phpif you want the template to apply to all instances of this field.Needless to say, however, it is actually possible to have a field whose machine readable name is
imagerather thanfield_imagewhile also having a content-type with a machine-readable name ofimage. In this case, having a template file named field--image.tpl.php would indeed be picked up for all fields being rendered for an image node.Since changing this would amount to an API change, this should probably be an 8.x issue. However, the task of fixing this specific issue might be moot depending on the resolutions taken for #1499460: [meta] New theme system and for #1382350: [discussion] Theme/render system problems
If not moot, my suggestion would be using a different naming convention where the field name, entity-type, and bundle have fixed locations in the name structure of a template file.
For example, if we use a convention like field-[FIELD_NAME]-[ENTITY_TYPE]-[BUNDLE_NAME].tpl.php, then we would have the following template names for the accompanying situations:
field--field_x--node--y.tpl.php: template file for all fields named "field_x" in the "y" bundle of the "node" entity-type.
field--field_x--node.tpl.php: template file for all fields named "field_x" in all entities of entity-type "node".
field----node.tpl.php: all fields that are in all entities of entity-type "node"
field--field_x.tpl.php: all fields named "field_x" regardless of entity and bundle.
field------y.tpl.php: all fields in all bundles named "y" in all entity-types (though I couldn't imagine a use case where we'd have bundles of the same name under different entity-types).
Comment #2
star-szrI think we can close this as a duplicate of #2229355: Field template suggestions are colliding.