Views are certainly one of the most sort-out Drupal modules and it’s believed that they will form a core part in Drupal 8.
This is a tutorial that will help you understand Views and educate you on creation of listings of content using the module. We will begin with learning creating a view, after that we will see the kind of listings and the content formats available. Once the look is finalized filtering and sorting are performed. This is an important step as it helps you determine what is to be displayed and how.
You must have installed Views before you learn how to use it. If it is installed, then navigate to “admin/structure/views” and get an overview of the Views that exist on the site. You will find that few of the Views are disabled. Views like ‘Front Page’ and ‘Taxonomy Terms’ are really handful as they copy and replace default Drupal behaviors.
Click ‘Add new view’ to get a View creation form for creating a view.
In this View creation form you need to enter the view name and filter the sort of information you like to be displayed by the view.
Here we have selected “content” (nodes) out of the other entries like terms, users, etc. Make sure you chose the correct option as you cannot change it later. Since we selected content, we get an option to select the type of content to display. The selection made here can be changed later while editing the view.
If you looked at the creation form closely, there were two more fieldsets “create a page” and “create a block”. These two options enable us to create display of our views.
A view can have multiple “displays” of varied types- block, feed, page, etc. some of these are available outside the box while others are provided by other contributed modules. Thus, a single view to display same content in different ways can be created using different filters, formats, etc.
But, in this article we are only dealing with the ‘Page’ display, so leave the other two options unchecked, and click ‘Continue and edit’. This actions takes you to the View edit page, where you should first click the save button to save the View.
On this page you get a “Displays” bar with a “Master”. Here we will create a page with a path to check our listing. Click on “Add”, select “Page” and give a display name. To select a page title, click on “None” under the ‘Title’ fieldset.
The point to note here is that while making these changes you’ll get the choice to apply these changes on current display or on all others. By default the selection is “All displays”, so be extra careful here.
Before checking the other settings, you have to specify a path for the View page. Since Views need to register with Drupal, you won’t be able to save the View unless you specify the path. You can specify the path by clicking on the “No path is set” tag found under ‘Page settings’. Then place the page it in a menu to specify an access rule for it.
The ‘Format’ fieldset presents different options to display the View along and what content is to be displayed. Unformatted list is the default pattern that is displayed.
Selecting unformatted list gives you the liberty to chose the number of Drupal fields (entity properties or fields declared via Field UI) you want to display on every field. There is another option that comes with Views: “content”.
Every content type in Drupal 7 has a few modes (full, RSS, teaser, etc) and for each of these modes you can specify different ways the fields will be displayed. For example, you will get different image style for full view mode than teaser.
Henceforth, the node to be displayed can be selected using a particular view mode. But, we are more interested in Fields as it lets us being in the realm of Views to prepare the output of every View row.
The “Sort criteria” section enables you to add fields that you can use for sorting the View. We’ll use the node authoring date (Content: Post date) and add it to the View for sorting the list in Descending order. However, you can even expose these fields to the end user to let them perform sorting on their own.
At the End
So, we have indeed created a simple View to display basic information related to the articles on the site. While doing it, we learned how a View is created and came across various possibilities in this context. Moreover, we created a page to render the View and learned how fields are added.
It was not an in-depth study, just the basics. Understanding the basics is very important before you take up the challenging work as Views is quite complex. Spend your time refining your skills if you want to succeed in working with Drupal.