There are many reasons why Drupal is a powerful content management system. Drupal is an open-source no licence fee platform, it is flexible, scalable, and works well with large amounts of content. One of the best features out of the box from Drupal is the Drupal views feature. In this article, we will talk about how views can be utilized and how complex they can go.
What are Drupal views?
In simple terms, a Drupal view displays a list of content. For example, if let’s say you are working on a film review website, and on the website, each film review has its own page with detailed information such as the title of the film, director, casts, producers, release date and so on. Drupal views, by default, can create a new page or a block that displays a list of the titles of films you have reviewed. You can also configure the view to show more than just the title, but also other content as needed.
What are the basic features of Drupal views?
Drupal views come with a few different display formats, they can be displayed as an HTML list, unformatted list or a table. Each format comes with some settings you can configure to fit your needs.
As mentioned above, this is where you can set which fields to display, such as the title of the film, director, release date and such. Depending on the field type, there are different settings you have to work with to display the content correctly.
Within each of these fields, you can configure what to display if the field is empty, you can also configure the classes, labels, wrappers to accommodate the styling needs. You can even leverage the rewrite results feature to add content or manage the layout of the fields you want to display.
Other than simply listing out the content, Drupal views can apply filters on the content being displayed. Let’s go back to the film review website example, let’s say you set up a view to display all the film titles on a page, you can utilize the filter to show films that are only released this year, or between certain dates. You can also expose the filter to users and it may display all the titles by default but the user can choose a date range filter to show a subset of titles. This can sometimes act as a search feature of the list of content which is useful when the list is complex or when there is a large amount of content to display.
This is where you can set how you want to order your list of content. You can choose from the different fields and set to as alphabetical, by date and allow the user to choose ascending or descending.
To make things easier, Drupal views provide a preview window right at the views configuration screen. It might be missing some styles compare to the front-end but it first shows the query of how this list of content is generated as well as a preview of how the results look like, this is very helpful when building a view because it saves time for the developer to have to switch back and forth to see what the display looks like.
Header footer no results behaviour and pager
Views by default provide a header and footer field that will display before and after the view itself, this is great for managing the layout and gives the developer the flexibility to work with the designs.
The no results behaviour field can be configured to show something if your view has no results to be displayed. The pager gives you some simple options you can set on how many items to display or if it needs pagination.
Advance features of Drupal views
So far we’ve been using Drupal views as a means to display a list of content that we’d like to display, with the fields, filter, sorting, header, footer...etc. But this does not apply to all the situations, sometimes, we want the view to display something according to the page we are on. Using our film review website example, let’s say we want to display a view on every film review that will show a list of films that are in the same genre as the film review you are looking at. With only the features mentioned above, you will have to create many different views with the same fields and same styling and layout but the only difference is the genre of the film. That is not very efficient
With a contextual filter, we can utilize this feature to let the view know how to check which genre of film the user is reading from and only display the films that are in the same genre. Think of contextual filters as a dynamic filter that can be used to update the filter criteria mentioned above depending on the page we are on. It can read the URL, the fields on the node and other information to display the correct view.
One of the Drupal CMS features is how fields can be reused in different content types, you can also utilize entity reference to show content or information from another content type. However, in a standard Drupal view, you can only choose one content type to display. What if I need to display some content or information from another content type? This is where the relationships feature comes into play. The relationships feature can link up different content types and allow the view to display information from another entity, such as taxonomy, vocabularies, or another content type.
If your filter criteria of the view have exposed filters for users to filter out information, this feature gives you some flexibility in how the exposed form should look like. You can install other contrib modules such as Better Exposed Filters to expand the functionality and flexibility of the exposed filters.
What if you need multiple views that are only slightly different?
In each Drupal view, there are options to have multiple displays. For example, let's say you built a view to display all the film reviews you have in a simple list format. But on another page, you need the view to look more like cards, it is almost the same but with cards, you need the view to display an image of the film.
Yes, you can create different views for it, but alternatively, you can add a display on the same view, you can have global settings across all view displays and you can have settings that only apply to one display and not the other.
Drupal views is a powerful tool that allows you to customize your display from something simple, such as showing a list of content from a content type. To something very complex with multiple relationships and contextual filters. It makes creating multiple displays easy and user-friendly. There is a reason why Drupal views are one of the most mentioned features of Drupal. Lastly, don’t forget to click save.
If you have any questions regarding anything Drupal, please feel free to reach out and we will be more than happy to help with your project.