0
votes

With Drupal 7 and Views 3, I'm trying to get the result of a call to views_embed_view with contextual filter arguments in hook_preprocess_node, for embedding into a node template.

The view is using the Fields display setting, including "Content: Title" and some custom fields. When I preview the view with contextual filter arguments from the Views UI, everything works as expected, but when I embed the view none of the node's fields from the Fields API are loaded (only the built-in attributes like title and node ID are loading).

Any idea what's going on here?

sites/all/themes/XXX/template.php

function XXX_preprocess_node(&$vars, $hook) {
  $node = $vars['node'];
  $vars['views__deals__single'] = views_embed_view('deals_single', 'page_1', $node->nid);
}

sites/all/themes/XXX/templates/node--deal.php

// ...
echo 'THE VIEW SHOULD BE HERE:';
echo $views__deals__single;
// ...

The result of the echo is the node title, and the HTML wrappers for the other view fields including labels but their content is empty, unlike in the view preview.

Help!

1

1 Answers

0
votes

You can just put it directly in the node.tpl.php template:

<?php print views_embed_view('deals_single', 'page_1', $node->nid); ?>