Drupal 7: Add view to content type

Woodgnome picture Woodgnome · Sep 27, 2012 · Viewed 14.2k times · Source

I've been making a template for a particular content type, but just ran into a problem: I need to embed a view into the content type.

I am aware this can be done via several different methods, but I don't see one that fits exactly my needs:

  • I need the view added automatically for all pages of that content type.
  • Using blocks in a region is not an option, as I want to avoid defining a region in the middle of a page that should only be available for a specific content type.
  • Translatable label.
  • Possibility to freely apply a template to all fields in the content type (excluding the embedded view).

I tried doing it via page layout (Panels) and simply adding node content fields and the view to my layout regions, but then I get another problem: I can't style my content fields without doing something that seems a bit over the top:

Currently I have about 20 different content fields in the content type that are wrapped in HTML and styled in my template file. I have a translated label for each of these in the template file. From what I can tell I'd have to add a template for each of the panes containing content fields to add my translated labels and HTML needed to style each field.

I'm not really fond of making 20 templates, 20 theme hook suggestions to get the templates to work and 20 regions in the panel layout just to get a view inserted in the content type.

Am I doing something terribly wrong here? Any suggestions?

Answer

nmc picture nmc · Sep 27, 2012

You may want to try the Viewfield module or similar modules (search for "view field" or "view reference").

If you are doing something more complex like changing/filtering the view based on some value in your content type, then you may have to use Viewfield module in combination with something else that will help fill in the filter values.

I've never done something like this before so I'm not sure exactly what module combination would work but Rules or Computed Field come to mind as possible helpers.