I have a body field view template:


 * @file
 * This template is used to print a single field in a view.
 * It is not actually used in default Views, as this is registered as a theme
 * function which has better performance. For single overrides, the template is
 * perfectly okay.
 * Variables available:
 * - $view: The view object
 * - $field: The field handler object that can process the input
 * - $row: The raw SQL result that can be used
 * - $output: The processed output that will normally be used.
 * When fetching output from the $row, this construct should be used:
 * $data = $row->{$field->field_alias}
 * The above will guarantee that you'll always get the correct data,
 * regardless of any changes in the aliasing that might happen if
 * the view is modified.
<?php print $output; ?>

What I want is:

if nid == 1
print $output =  view_embed_view('my custom view')
print $output;

How can we do this?

Note: I'm already using the Views Field View module, but can't figure out as how to apply this condition of nid.

  • 1
    I don't understand your question....
    – Jimmy Ko
    Aug 3, 2016 at 10:23
  • Actually I want to embed view on basis of node id. So if node id == 1 or something else, I will replace body field content with some other view. Aug 3, 2016 at 10:34
  • Views Field View may help.
    – Jimmy Ko
    Aug 3, 2016 at 10:48
  • I'm already using this module, but can't figure out as how to apply this condition of nid? Aug 3, 2016 at 11:23
  • 1
    You can take a look my answer in other post.
    – Jimmy Ko
    Aug 3, 2016 at 11:36

1 Answer 1


In view template file of body field, write this code;

$nid = $row->nid;
$body = $row->body;
if($nid == 1):
  $view = views_get_view('VIEWS_MACHINE_NAME');
  $new_view = $view->preview('DISPLAY_ID');
  print render($new_view);
else :
  print $body;

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.