1

I have a custom node (article) template file working fine, and I want to show related nodes (events) in their teaser format. I have been doing this in my node--article.tpl.php file like this:

foreach ($field_related_event as $event_node){
    print render(node_view(node_load($event_node['nid']), 'teaser')); 
}

I wanted to add a second teaser format for events (teaser_fancy) and downloaded "Entity view modes" thinking I would be able to do something like this:

foreach ($field_related_event as $event_node){
    print render(node_view(node_load($event_node['nid']), 'teaser_fancy')); 
}

But now I read that node_view can only use teaser and full, and it's probably not a good idea to render relationships in my template this way. What's the recommended way to go about this? Should I create an Events Fancy view and use views_embed_view instead?

1 Answer 1

0

A valid "view_mode" should work with node_view and that approach looks reasonable.

However, if it's proving problematic, you can also use Views with views_embed_view

e.g

print views_embed_view('viewname', 'display_id', $node->nid); // node id contextual filter
1
  • Thanks that's what I suspected. Do you think there is a big downside to using rendering the way I am is I want all related items?
    – summer
    Commented Jan 23, 2013 at 16:18

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.