2

I want to embed a view into the body of a node on Drupal 7. I've tried the module Insert View and that didn't work.

I also saw support from Drupal on inputting PHP code, but I have no idea where to put that code.

0

The best solution I've found so far is the Insert View module. It allows you to use tokens in the textarea to insert views wherever you'd like.

The UX of having to write out the token may be the biggest downside. I'd personally like to see a WYSIWYG button created to make use of this (similar to Token Insert Entity), but it's not too tricky to educate users how to use it by typing the token.

Other negatives could be potential performance and security concerns. As it says in the README.txt:

SECURITY WARNING

This filter is powerful, therefore it should be granted to trusted users only. If you allow this filter to untrusted users, then you have to make sure that EVERY VIEW EVERY DISPLAY (default display also!) has correct views access settings.

PERFORMANCE

To display views correctly, Insert view turns off caching for the input formats for which it is enabled. That means every node using this input format will not be cacheable. This can impact site performance. In these cases, it is recommended to create a special input format for use when inserting views.

  • That's what I ended up using. The readme.txt did an awful job at explaining how to use the damn thing, but I eventually found out how it worked. It works great and I can pass it off to my clients when my project is over. – user3411192 Mar 12 '15 at 18:35
6

When I want to display a View on certain content types, I make use of the functionality offered by the EVA: Entity Views Attachment module. On the entity's Field Display administration page, you can (like any other field) set the order for outputting the Views' result.

An interesting feature of the EVA: Entity Views Attachment module is that it allows to pass any token generated from the specific entity to the View as an argument.

  • Not sure why "this" answer is not marked as the "accepted" answer ... which I believe does not suffer those security/performance issue as in the accepted answer, right? Anyway: another +1 ... – Pierre.Vriens Jul 10 '15 at 10:21
  • 1
    Because the question was about putting a view within the body text — not to embed the view within a separate field, or at the top/bottom of the body field. You'll want to do that if you need a particular view to appear between two paragraphs in the body field. – davidneedham Oct 5 '15 at 9:36
2

You can use views_embed_views().

<?php 
print  views_embed_view('view-name', 'display-name','arguments'); 
?>

Put that in your page.tpl.php or other relevant template file in your theme. Use Devel to find out which template the page is using if needed.

Or you can use the block display on the view and assign your block to the main content region as well.

There are several ways to accomplish this task. I recommend checking out the doc link above and reading the comments for other ways as well.

  • So I've seen that "solution" too, but I wanted to know what I do to embed the view in a specific node. For example, if a user views my Resources page, I want them to be able to see the view that I created for that page plus the content that's already on it. – user3411192 Jan 7 '15 at 19:31
  • Make a block display in the views UI and restrict that block to only show on that URL in the block UI. You can place the block in the content region to either show above or below the main content of the page. – burnsjeremy Jan 7 '15 at 19:38
  • I got that done, but the block still shows on all pages of the content type I'm using. – user3411192 Jan 7 '15 at 20:08
  • In the block settings there is a show on certain pages setting, admin/structure/block then hit configure on the block view and the settings will be on the pages tab – burnsjeremy Jan 7 '15 at 20:10
  • You can use wildcards or just specify URL like node/1 or the alias of the URL if the radio "Only the listed pages" is set – burnsjeremy Jan 7 '15 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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