Saturday, September 24, 2011

Drupal Views

Drupal Views

My first experience with Drupal Views was due to the fact that it was a requirement by other modules. But once you understand what views brings to the table, you will quickly understand why it is such a powerful and almost a must have module for every Drupal installation. I am not an expert on views, I am merely publishing what I learned so far. With the disclaimer done, lets get to the actual content -

Views for Drupal is a fexlible module which allows an administrator to define logic to gather content published in the system and define how the matching content is displayed.

Think of content as data spread across different tables in a database. Similar to how a database view allows you to bring related information into a single object, Views module extends the same same functionality to Drupal.

Logic to get content from the system include the definition of what content is pulled from the system (filter - eg: Nodes of type Article) and what information is pulled from the system. The resulting content is presented as per the definition of the "display" for the view.

The same view can have multiple display types - eg: display within a block, display in a page and each display can be different - eg: the page display can show the snippet of the content where as the block display can be configured to display only the title of the nodes.

To install Views module, you need the Chaos module installed in the system. Please refer to the installation requirements as there might be a need to install a minimum installation of the required dependencies.

Views 3 modules comes 2 sub modules - Views, Views UI. Views itself is the core module and Views UI is the submodule which allows you to create and manage views.

Views Terminology:

TITLE

String that will be used as the title in various displays. You can set different title for differnet display types - eg: you can set the title of the page to "My Articles Page" and the title of the block to "My Articles widget". You could choose to use the same title on all displays too - eg: "My Articles"

FORMAT

You can define how the matching content gets displayed on the format defintion. Possible format types include -

Grid - Content is organized by rows and columns (similar to content on news paper)

HTML List - Content is displayed one after the another (similar to the default drupal front page)

Jump Menu – Matching content is displayed in a drop down and the user may make a selection to view the appropriate content.

Table – Content is laid out in a table with the selected fields in the column.

Unformatted list – lists each matching content one by one similar to HTML list – but provides less customization options.

Each format type has additional settings which define how the content is formatted – including ability to specify custom CSS class, how fields are displayed etc.

You can choose different format for each display – example: you can use a simple unformatted list for the block display whereas the same view can have Grid type display for the page.

FIELDS

Define what content needs to be pulled for the view. These fields will be used in format to define how they are presented.

FILTER CRITERIA

Allows you to specify conditions which limit the content to specific criteria.

Filters are further enhanced by the user of “Relationships” defined later which you to add additional objects which can be used on the filter.

SORT CRITERIA

Allows you to define how the content is sorted in the display.

PAGE / BLOCK SETTINGS

Allows you to control the behavior of the container – a block or a page. You can define the name and path of the page or the block, whether the link should added to a menu, who can access the display, paging options etc.

CONTEXTUAL FILTERS

Contextual filters allow you to user parameters passed to the page (say via URL) to be used as filters.

Eg:

http://yourdrupalsite/view-page/user/user1

http://yourdrupalsite/view-page/user/user2

Assuming “user” is the contextual filter, the first URL can be used to pass “user1” as the value for the filter whereas the second URL will pass “user2” as the value.

Contextual filters need not necessarily be URL based. They can also be fixed value / based on a PHP code / based on the user account who has logged in etc.

With the help of contextual filters, you are able to setup dynamic filters for the view.

RELATIONSHIPS

Relationships allow you to define how objects are related. With this feature, you can define non-explicit relationships. Explicit relationships are defined by the views module itself – example: A node to an user – where you are able to filter nodes authored by specific user. With the relationship option, you are able to define additional relations – like a file to a node etc.

OTHER

All other miscellaneous options are grouped here.

Use AJAX – use AJAX functionality for elements like page navigation etc.

Query options – allows to override default Drupal rewrite (to include node access checks) etc.

CSS Names – Additional CSS classes that needs to be added to this display

Conclusion

The view module is a versatile way to obtain content from the Drupal system and display it on your site. A typical use case scenario would be – you want to display “Nodes authored by a specific/current user”, content on specific type to be listed on the Frontpage or other sections of the site. The features and the customizable nature of this module makes it almost a MUST have for every Drupal installation.

2 comments:

Anonymous said...

Can I simply just say what a comfort to uncover an individual who genuinely knows
what they are talking about on the internet. You definitely realize how to bring a problem to light
and make it important. More and more people ought to read this and understand this side of
your story. It's surprising you are not more popular because you surely possess the gift.

Have a look at my homepage :: http://managingdirectors.in/

Anonymous said...

Hmm is anyone else encountering problems with the images on this blog loading?
I'm trying to find out if its a problem on my end or if it's
the blog. Any feedback would be greatly appreciated.


Visit my web blog ... レイバン 通販