In Drupal 6 a view can be embedded into a node as follows:
$viewName = 'LatestNews'; print views_embed_view($viewName);
This does not work for drupal 7. What is the function to embed views in drupal 7?
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 community
The EVA module can also attach views to nodes.
To display a view in a node template, you use the following code.
// Load the view. $view = views_get_view('machine_name_of_view'); // Set the active display. $view->set_display('your_view_display_name'); // Set any needed argument. $view->set_arguments(array(arg(0), arg(1))); // Execute the view. $view->execute(); // Render the view. print $view->render();
print views_embed_view($view_machine_name, $view_display_name, $arg1, $arg2);
where $arg, $arg2, etc are optional.
Or use Viewfield module to embed a view as a field.
One solution is to use Panelizer to override the content of the respective node.
Lets say for example you have a handfull of one-off pages that need a view attached.
1) You could use the Page content type or maybe create a new content type that will specifically be panelized.
2) Enable Panelizer for that content type, make sure to set it up to "Allow per-record display choice" that way you can setup multiple panelizer displays that will be tailored to each one off page. (each panelizer display can have it's own set of views attached)
3) From here you simply create a view (I like to use Content Panes for this) and add it to the Panelizer content display of choice.
This allows you to re-use a single content type that doesn't really need it's own set of fields, but might potentially be used for either referencing other entities (as a field) or referencing views.
Throw in the Paragraphs module and you have a Swiss Army Knife content type. Speaking of, that would make a perfect name for the custom content type used for this purpose... Hmm....
Let's just mention that first parameter is view name, second display name and after that you can pass contextual filter parameters.
So that "$node-nid", the third parameter depends on you view...what it expects for first contextual filter - id doesn't have to be node id. Of course, you are not limited to one parameter - pass as many as you have in view...or pass none if your view doesn't have contextual filters.
A very configurable Drupal 7 and 8 module is views_field_formatter which allows you to embed a view as a fields formatter