This screencast is available at http://rapidshare.com/files/78037463/drupal_views_screencast.mp4 and http://blip.tv/file/553914
This screencast covers the installation and configuration of the views module, as well as:
- Creating a new view (both page and block)
- Adding arguments to the url for a page view
- Using views to create an RSS feed
- Using fields to customize the layout of list and table views
- Overview of filters and exposed filters
- Basic Performance considerations of views
This is the script for the screencast:
This screen cast is going to teach you the basics of using the views module in drupal. First we have to download the views module. To do this, go to http://www.drupal.org/project/views and click on download.
Once the download is complete, extract the views module.
Once the extraction is finished, move the files into the modules folder.
Configuration of the Views Module
To configure views, go to the modules page, scroll down, and make sure that all the views components are enabled. Once everything is working as it should, there should be an extra tab under site building - views.
Creating a View
Say i want to create a blog replica using views. To do this, go to views, and click add. Enter a name. Because this is going to be a page and not a block, I have to select 'provide page view' under page. Enter a url and a title as you see fit. Because I want the most recent posts to come first, I have to add a particular sort criteria - node created time, and change the default sorting to descending.
Views can also filter a list based on arguments passed to it in the url. For example, if you only wanted to see posts by one user in particular, you would add a placeholder argument to the url by typing '$arg' and defining the argument. To do this, go to arguments and add the relevant argument type. In this case, you would want 'uid as author' because you're selecting posts by one user.
Under title add recent posts by '%1'. The '%1' tells the views module that it has to replace it with the value of the first argument. Similarly, using '%2' would tell the views module to replace it with the value of the second argument.
A wildcard is a value for the argument that will return all applicable values. If used in this case, it would return all the posts no matter which user wrote them. Wildcard sub is just the text that the views module would use in the title instead of '%1' when the wildcard is used.
The output of this view is a page that changes the contents of the list shown dependent on the argument in the url entered.
There are a number of arguments that you can use, one of which is 'taxonomy term name'. If you use this argument along with a vocabulary that posts are tagged with, it is possible to display a list of posts with a certain tag.
Views can also create a RSS feed for any list. For example, to add a RSS feed to our blog, I would edit the view and add a special argument, 'RSS feed selector'. It is special because it does not need an argument placeholder in the url. Simply append '/feed' to a view which has a RSS feed selector argument, and you will be given a RSS feed page.
Creating a Block
In addition to pages, views can create blocks. The steps to create blocks are almost identical to the steps to create pages with a few major differences. Instead of selecting 'provide page view', you have to select 'provide block'. Also, you don't specify a url. Instead, you go to site building and click blocks. Then, you find your created block and select the location that you want your block to appear in. Once you click save blocks, the page will reload with your block in the location you've chosen.
You can customize certain aspects of your created views. An example of this is changing the fields that the block will show. For example, if you would like author's name, time created and the title of the post instead of the full post or a teaser post, such a view is easily set up. To customize the fields, the view has to use either list view or table view. However, it does not matter whether the view is going to be a page or a block. Once the type of view is selected, the fields must be added. In this case, we are going to add the post title, the date it was posted and the author's name. You can arrange the fields in any order you like. We are going to arrange it in the order author's name, date posted, then title of post. Once the arrangement is to your liking, simply click save to have your view use your customized layout.
Filters & Exposed Filters
Another feature drupal provides is exposed filters. Exposed filters are essentially filters that are accessible to any visitor of your website, while acting just like normal filters. To use an exposed filter, you first have to create a normal filter, then click expose.
One example of exposed filters is limiting your search by keywords/taxonomy. To do this, you have to expose 2 filters: 'search:Index' and 'Taxonomy:terms'. Once you do this, you will be able to search for your words in posts with a certain keyword/taxonomy term.
As you can see, selecting a tag and using a search term gives a more accurate result than simply selecting a tag or using a search term by itself.
The performance of views is dependent on 2 things: how complicated your view is, and how heavily loaded your database is. If your view is complicated, for example a view with many different fields such as author name, date posted, date updated, comments, etc, that means that each time your view is accessed, your database is going to get many requests as views does a separate request for each field. Thus, if your database is heavily loaded, the performance would be slower. Conversely, if your view is relatively simple, and your database load is light, the performance of views would be much faster. However, you shouldn't have to worry much about your views performance unless you're running a very big site.
One way to speed up views is to reduce the number of queries to the database that need to be made to display a given view. The easiest method is to reduce the number of fields shown in a particular view, such that fewer queries are needed to display that view.