In Drupal 7, I have a View that works great but I'd like to add a few nodes into the result arbitrarily outside of the scope of the View.

Basically, let's see the View returns Content Type X, I want to include a few nodes from Content Type Y that are in addition to whatever the View generates from Content Type X.

My preliminary thought was to use hook_views_pre_render but I'm not convinced that is the best solution....yet.

  • Add a filter of "content is of type", select X and Y on check list. – No Sssweat Sep 16 '15 at 13:55
  • @NoSssweat The problem with that is I would get all of Content Type Y included. I just want a subset of Content Type Y to be included with all of the results of Content Type X – Matt Sep 16 '15 at 13:59
  • can you draw a picture/diagram on how that would look like? – No Sssweat Sep 16 '15 at 14:01
  • @NoSssweat I apologize for not being clearer. Let's say I create a view for Content Type X and it returns 10 nodes. I want to include 4 other nodes in the result that would not (and cannot) pass the filter for the original view. Does that make sense? – Matt Sep 16 '15 at 14:20
  • Are these other Y nodes displayed, at the bottom, after the 10 nodes of X? Or are they mingled with the X nodes? PS: I am a visual person, a diagram or picture will def help. – No Sssweat Sep 17 '15 at 3:40

You may want to use hook_views_pre_execute (see example) or hook_views_post_render() where you can add arbitrarily content (new rows or html code) into the view to fake the nodes.

Please check the following code example to give you some idea.

You may also compare how other Views-based modules doing non-database query results, such as Search API Views or YQL Views Query Backend.

| improve this answer | |

Maybe Views Field View module can help with that, you can create a view for X content type, and embed a another view in it as a field that show Content type Y.

| improve this answer | |
  • It looks like this will just tack on the additional view in the same way an Attachment would, right? – Matt Sep 16 '15 at 14:28
  • no this is different because you can dynamically load another view, or you can pass arguments or use tokens. – sam2de Sep 16 '15 at 14:38
  • Tried using the module but one problem: The view does not use fields, it displays teaser. I tried sticking it in the View header or footer, but then it's outside the results. – Matt Sep 16 '15 at 14:53
  • This might help Views node field. so you can use Fields and render your teaser as well. – sam2de Sep 16 '15 at 15:22

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.