I have a node type for which I have a custom tpl. OK.
But this node type I also have as a referenced entity in another nodetype. And in this case I need another custom tpl.
Is it possible to have another tpl and if yes: how do I name this file?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityWhat you can do is to add a custom view mode for your node type, and then use the new view mode for your entity reference field. You have a couple of options, depending on whether you want to code a custom module, or stick with available contrib modules.
The entity view modes module will allow you to add your new view mode, or you can use hook_entity_info to programatically add a new view mode in a module you write yourself. This article provides an example of adding a view mode with hook_entity_info:
function acme_view_modes_entity_info_alter(&$entity_info) {
// Define the view modes
$entity_info['node']['view modes'] += array(
'featured_story' => array(
'label' => t('Featured Story'),
'custom settings' => TRUE,
),
'secondary_story' => array(
'label' => t('Secondary Story'),
'custom settings' => TRUE,
),
// Define more in this array as needed, e.g. tertiary_story
);
}
That same article also provides an overview of adding theme hook suggestions so you can supply the name you want to use for your template (the entity view modes module will handle this step for you).
For selecting the new view mode to use for the display of your entity reference, which you do on the "manage display" tab of your content type that includes the entity reference field, choose "Rendered Entity" as the Format for the field's display, then a settings-gear button will appear to the right of it. Click that button and among the available settings will be a select element to choose the view mode.