1

Using Drupal 7 I have setup a structure in which a widget_set content type has a node reference field that allows the user to choose nodes of the content_widget content type.

The template files are node--widget_set.tpl.php and node--content_widget.tpl.php

Inside the node--widget_set.tpl.php template, I call print render($content); and was hoping to have the output be formatted as specified in node--content_widget.tpl.php, but I just get output that seems to ignore the content_widget template.

Is that the expected behavior? I could just pull the code from the content_widget template into the widget_set template but I have a bunch of content_widget types and wanted to keep them all separate.

Thanks.

0

3 Answers 3

1

Assuming you want the structure to be something like this:

<div class='node node-widget_set'>
  <!-- other fields -->

  <div class='node node-content_widget'>
  </div>
</div>

ie, render the template inside the the other template, and assuming you have named your templates properly, put them in your theme, and cleared the theme registry (or cleared all caches), you need to set the display settings appropriately.

enter image description here

In the Manage Display settings for Widget Set, find the Content Widget field, and adjust the settings:

  • Set the Label as you need
  • Set the Format to Rendered entity
  • The click the gear, and adjust the settings. You can pick the view mode (full, teaser, etc), whether to show links or not, and potentially other settings that modules have defined.

Note that this does assume your node-to-node fields are using Entity References and not Node References.

Then you should get output to use nested templates. Using Entity View Modes and Rabbit Hole also come in very handy when you do things like this on your site.

1
  • OK, so I went through and tried everything from scratch again, and it appears I can done something incorrectly the first time around, because this time it's working perfectly. Thanks @MPD.
    – evanmcd
    Commented Jan 14, 2014 at 14:29
0

Drupal will only use one node template file based on the template suggestions. So if you have two content types Drupal will look for node--[type].tpl.php first and if that is not found then use node.tpl.php.

One node template file will not inherit from another node template file. So you'll need to create two node template files, one for each content type.

0

If you need to share one template between two types then the easiest way is to add something like this to your template.php file. Sorry if I missed the point I did not completely understand the problem.

function hook_base_preprocess_node(&$variables) {

    if(node_is_page($variables['node']) && ($variables['type'] == 'node-type1' || $variables['type'] == 'node-type2')){
      $variables['theme_hook_suggestions'][] = 'node__your_template';

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.