Using the Views Module in Drupal Content Management System
A content management system is a database. As such its power lies in the processing of data, in this case the content of the web site. This involves building queries to select and sort the data that you require. This can be achieved with programming in PHP, but this is a complex task for many users.
Using The Views Module in Drupal
Drupal provides the Views module to query the content of the database and generate bespoke datasets which can provided as pages, blocks or RSS feeds. The module is not part of the Drupal core but must be downloaded and installed. This is a familiar process because it is similar to the initial installation. Just don’t forget to enable the module in the list of modules! The views module is in essence a query generator which saves the user the task of programming their own queries. Even this can seem relatively complex, but the getting started guide within Drupal provides an approachable guide to the process of creating a bespoke view.
Using The Views Module in Drupal: An Example Application
The website www.alangillies.com has at its heart content which consists of news items stored within Drupal as blog items and opinion pieces stored as stories. The design called for the ability to produce bespoke pages providing separate access to the news items and opinion pieces, and to mirror those pages in RSS feeds.
To create a page of story items such as the opinion pieces at www.alangillies.com, the following steps are required:
1. Log onto the site as the “superuser” with full administrative rights.
2. Select “Administer”
3. From the Administer menu, select “Views” from the “Site Building”
4. Click on Add
5.At the next screen, a name and description are needed, and the type is set to “Node”. This screen is now complete and Next takes the user to the screen where the query itself is constructed.
The default view to be created is a Page, so we can leave this as is and
6. Select the field to display
a. In 3rd column locate the Fields options. Click the + icon to add fields.
b. Scroll down to Defaults: Add fields. In the Groups drop-down menu select ‘Node’, then check the following field: Node: Node Title.
c. Then click Add.
d. The system will then offer you the chance to change the options associated with this field. For the Title field: Delete the ‘Title’ label. Select Link this field to its node.
e. Click Update.
7. Filtering to story nodes only
a. Click the + icon next to Filters.
b. In the Groups drop-down menu select ‘Node’, then check the Node: Published and Node: Type filters, and click Add.
c. Select the Published checkbox. Click Update
d. Select Is one of and check Story in the Node Type field. Click Update.
8. Sorting to show most recent first
a. Scroll up to Sort criteria and click the + icon.
b. In the Groups drop-down menu below, select ‘Node’, then check Node: Post date, and click Add. Alternatively, you may instead check Node: Last comment time, or Node: Updated/commented date, or Node: Updated date.
c. Select Descending Sort order. Click Update.
9. Refining the basic settings
In the 1st column under Basic settings change the following options:
a. Items to Display setting, click on 10 and change the “10” to “6”.
b. Click Update
c. At the Style setting, click on Unformatted and change to List.
d. Click Update.
10. Creating the bespoke page
a. In the dropdown on the left, ensure that Page is selected, and click Add Display.
b. Under Page settings, click the None link next to the Path setting.
c. Give the page a path so it can be managed with Drupal.
d. Click the None link next to the Menu setting, and attach the new page to the menu of your choice
11. Saving the view
a. Click Save to save your work.
Usability (3 out of 5)
Using the Views module is easier than programming in native PHP but still not as straightforward as other Drupal modules. Still, if you have got this far, the effort required to learn how to use the Views module in Drupal is worthwhile.
Flexibility (4 out of 5)
The views module is less flexible than native PHP but still provides major flexibility. This flexibility is why you needed a content management system in the first place. If you didn’t: HTML is very nice.
Documentation (3 out of 5)
Documentation provided is limited and not especially helpful or easy to understand, although some YouTube videos are worth watching, if you are struggling.
The query function is at the heart of any database. The Views module provides an easier way to write queries than PHP programming, and the getting started guide does a good job of guiding the inexperienced user. There is also a a growing body of instructive videos on YouTube to help you.
This post is part of the series: Drupal
Drupal is a powerful open source content management system. This series of articles reviews its usability for an intermediate user with no prior knowledge of PHP and MySQL developing on a Vista running PC and a third party server.