Views and Panel Overrides

Wed, 12/02/2014 - 10:12

If building Drupal websites has taught me anything, it’s that your solution isn’t always the correct one. But then again, which Drupal solution is ever really correct? There are many ways to get to the same result and it all just boils down to user preference.

There have been a few office debates around Display Suite vs Views. Display Suite is great for smaller more rigid websites, since the content requirement is low and you get out of all those joins that views throw at you. When moving to larger scale, complex, media-rich websites views become a necessity.

When looking at your default node pages, it seems impossible to get a view onto that page without some wizardry that you would only find hidden in some forum topic. Fear not, this post will give you the ins and outs of how to override your default node page and create simple landing pages.

Building blocks

The first thing you have to do is to draw up a plan.

Plan out your content types, select your fields and get a rough sketch together what each content type node page and landing page will look like.

After your content types are sorted and you have an idea of what you want to do on your landing page you can begin with building your view. A tip here is first build your landing page view on the default display. This will require less effort when adding more displays. You can carry on building your view as you normally do. Once you’re happy with your landing page view, add a “Content Pane” display. Remember to update your display name, my favourite naming convention is “Pane: Article Landing” or “Pane: Article Specific” for my article landing and node page respectively. Your Landing page view should look something like this:

View Content Pane Display

A basic article landing page content pane display.

The next step would be to build your node or article specific page.

You can simply add another Content Pane display, rename it and choose which fields you want to render. There is one problem though… How will the page you are on know what node’s content has to be displayed? This is where the dreaded “Advanced” tab comes in; mainly dreaded because the sheer number of options there seems daunting.

Fret not, we are keeping it simple. Under Advanced you will simply add a contextual filter that tells your view to only show content related to the NID (node ID) of the current page. Your view will look something like this:

Display of a Content Management System

Article Specific page with a contextual filter set to NID which provides a default value from the content URL (essentially checking the NID to know what should be shown).

Panel Overrides

Your views are done, but how do you navigate to them? Here you would have to start using panel overrides. Instead of creating custom Pages you can enable the Node template (/node/%node) Page Template. This template enables the use of selection rules to target specific Node IDs or Content Types. Below you will find an example of overrides:

Drupal panel overrides

The 3 most common overrides you would use is node, user, and term as per the example above.

The more content types you have the more variants you will have listed in your Node template, so there are some fundamental tips you should take note of:

Variants work hierarchically: This means that a variant with general/”catch all” selection rules (node type: article) will be executed instead of one with a selection rule that targets a NID specifically if the specific override is situated below the general override. So keep specifics high and generals low to ensure that all overrides fire independently.

Naming conventions: This section can become extremely cluttered so ensure that you use clear and concise naming conventions. I prefer naming my overrides the same as my views. That way you know what view you referenced and what will be in the override before inspecting it.

Groupings: Group content type specific variants together. I.e. Article specific page, Article landing page, etc.

Linking views to overrides

This would be the last step in the process. On the content section of your variant you will be able to access a number of elements; from node fields, widgets, page elements and views. Take a look at the example below to see all the options:

Display of a dashboard panel

Various options you can select from. Just note that a lot of these options would depend on what modules you have installed.

You will select the View panes category where you will be presented with a list of all Content pane displays on the website. You will simply select it, override the title and save.

Congratulations! You have completed one of the most useful and powerful content presentation techniques on Drupal. Given, this example contains the bare minimum required to do an override, but this should enable you to effortlessly expand and birth panel panes all over the show.

Need Assistance with Digital Strategy?

Rogerwilco’s team of strategists, business analysts and data scientists is here to help.