Want to contact me by voice?
(720) 254-1546

A Recipe for a Rapid Drupal Site--Part IV, A REALLY Basic Introduction to Views

After you have your content types set up, you can use Views to create custom pages and blocks.  In the case of TraumaAdoption.org we created a couple of pages and a few blocks with lists and pagers at the bottom.  This post won't cover more than just the basics of using Views.  Greg Knaddison did a great screencast on using Views.

The current version of Views has a pretty steep learning curve, but once you've learned the basics the amount of power to control outputs without being a developer is pretty significant.

views

We'll walk through the steps to create a simple page and a block with node titles.

The Steps...(Save OFTEN while going through these steps)

  1. Go to /admin/build/views.
  2. Click on the "Add" Tab.
  3. Give your View a name, a description, and a tag.  For the purpose of this example, leave the "node" radio button selected.
  4. Click "Next".
  5. At this point you are looking at the default view.  You can set some global options here for your set of Views.
  6. Give the default View a Name--Something like "Default Book Review"--that describes what you want this View to do.
  7. Give it a Title
  8. Click on "Use Pager" and choose "Full Pager" and click "Update"
  9. Click on the + beside "Fields".  You can filter your choices with the pulldown below "Add Fields".  Choose "Node" and then select "Body", "Post Date" and click "Add" and click update in the same box below for each field.  Repeat for "Node" "Title". If you click on the "exclude from display" it will cause the field not to be part of your page view.  You can also choose to move the fields around using the arrow icon and then drag and drop in the window below.
  10. Go through the same steps for different kinds of fields like the User name.
  11. Now we need to filter the results.  We'll create a very simple filter.  Click the plus beside "Filters".
  12. Check off  "Node Type".
  13. Click "Add".
  14. Choose the Node Type you want to filter by.
  15. Click the plus beside "Filters".
  16. Choose "Node" and "Published".
  17. Click "Add" and check the "Published" box.
  18. Click "Update".
  19. Click "Save".

If at this point you click on Analyze, it will indicate that you've done everything that you need to do for the default View, but that you don't have a page or a block yet.

The default view will work great for a page.  Up top on the left, leave the pulldown on "page" and click "Add Display".

  1. Go through the same steps of changing the name and title--but reflect that this is the "Page" version of your view.
  2. In "Page Settings" add a path name--that is where the page view will show up on your site.
  3. If you want your page view be included in your menu, Click on "Menu" and choose the radio button for the menu type you want to include.
  4. Click "Update" and "Save".

You now have a simple page view set up.

Now lets create a block. Up top on the left, change the pulldown to "block" and click on "Add Display".

  1. Go through the same steps of changing the name and title--but reflect that this is the "Block" version of your view.
  2. I want to only have the title show up and I want it to be linked.  Click on "Node: Title" in "Fields".  Click on "Link this field to its node".  Click "Update".
  3. Click on each of the other fields and click on "Exclude from Display". Click "Update".
  4. Click "Save".

Your Block Menu /admin/build/block should now have your new block.  If you drag it to a region and update it, it should show up in that region.

When you are creating your block or page you will sometimes be given the option to override or modify the default view.  If you want to leave the default view alone to work from, use overrides.

Thanks to Merlin of Chaos for developing and sharing Views.

The next post in this series will cover all sorts of small sundries to start buttoning up site details.

Comments

Why do you suggest saving often? Views is really good about keeping the working data cached so the most you can ever lose by navigating away from the form is the fields that you might have open on the form at the time. If you navigate back (and if you used the 'back' button, hit reload to update the browser cache) you'll always get back to the last state you were at.

Saving is an unfortunately time consuming operation (it forces a menu rebuild which takes several seconds) so saving often during editing seems unnecessary to me.

When I first started using Views2 somehow I managed to lose much of the work I had done on a default view. It is good to know that my experience that time isn't the norm.

That problem likely appears because the browser caches. So when you navigate away from the page, and then go back to it, the browser didn't reload the page from the server but used the cached one it had. This page has much older information on it, because none of the AJAX modifications to the page actually ended up in the cache.

The solution: Hit reload.

Thanks for the tip!