Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Drupal 5 Views Recipes
Drupal 5 Views Recipes

Drupal 5 Views Recipes: 94 recipes to develop custom content displays for your Drupal web site

eBook
$9.99 $32.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Drupal 5 Views Recipes

Chapter 1. Introduction to Views

In this chapter, we'll create both a page and a block using the Views module. We'll install Views, and introduce the Basic Info, Page, Block, Fields, and Filters fieldsets. We'll have a chance to further observe every available Views UI fieldset in Recipe 9. The Views Worksheet in Recipe 10 summarizes the whole interface, and will help you track your learning throughout the book. While most chapters lend themselves to a pick-and-choose approach, I encourage you to complete each recipe in this chapter.

Let's Begin!

Recipe 1: Installing the Views module


Note

Ingredients *

Drupal 5: http://drupal.org

Host login access

Views: http://drupal.org/project/views

Views UI: contained within the Views module

*These ingredients are prerequisite for all of the recipes that follow, and will not be listed in subsequent ingredient lists.

The Views module has a straightforward installation, much like other Drupal module installs. The following recipe instructions incorporate a mix of Windows tools and the command line for locating files, creating directories, downloading files, and unzipping them. Consider following the recipe, but feel free to substitute file management approaches specific to your operating system and preferences. This recipe is followed by a page listing helpful command line shortcuts that you should incorporate into your practice if they are available on your host.

Finding or creating the <DRUPALROOT>/sites/all/modules directory

  1. Log in to your web server. You will need to know your host name, login name, and password.

  2. Locate the Drupal root directory on your server (a common directory location is /home/your_account/public_html).

  3. If this is the first contributed module in a brand new Drupal installation, you will need to create the modules subdirectory.

    • From your Drupal root directory, type the following to change into the <DRUPALROOT>/sites/all directory:

      cd sites/all
      
    • Make a new modules directory:

      mkdir modules
      
    • While you're there, you may as well create the theme directory, if it is not there already. We will use this directory in Chapter 7, Techniques for Theming Views

      mkdir themes
      
    • Now change to the modules directory:

      cd modules
      

Downloading and uncompressing the module

  1. Open the browser of your choice.

    Note

    Most of the screenshots in this book use the Firefox browser—a popular choice for many developers. Recipe 8 covers Firefox installation.

    Go to http://drupal.org/project/views, and read the page. There are several different versions of Views available for download. We are looking for the Download link marked Recommended for 5.x.

  2. Download the module from the Views project web page. Here is one way to do that:

    • Right-click in Firefox on Download.

    • Select Copy Link Location (in Internet Explorer, this link will be called Copy Shortcut). You now have text similar to the following in your clipboard:

      http://ftp.drupal.org/files/projects/views-5.x-1.6.tar.gz

      A file with the .tar.gz extension is affectionately known as a "tarball", reflecting the days when files were backed up onto tape archives.

    • Switch to your Drupal server window. Be sure you are still in your <DRUPALROOT>/sites/all/modules directory.

    • Type:

      wget <Paste><Enter>

      Note

      In many shell environments, you can use the right mouse button to paste text from the clipboard. In Windows, you can use Ctrl+V.

    • The result on your screen, after pasting the download link, will be:

      wget http://ftp.drupal.org/files/projects/views-5.x-1.6.tar.gz
      

    After pressing Enter, the download begins. You are provided with a status report of the percent complete as shown in the following screenshot:

  3. Uncompress the module to the <DRUPALROOT>/sites/all/modules/views directory. Enter:

    tar xvf views-5.x-1.5.tar.gz
    

    Depending on your system setup, you may need syntax such as this:

    tar -zxvf views-5.x-1.5.tar.gz
    

    You may also use an alternative uncompression tool, such as 7-Zip or WinRAR. WinRAR offers a graphical interface in Windows, but is also available with a command line interface for Mac and Linux systems. The output of the tar xvf views-5.x-1.5.tar.gz command is seen in the following screenshot:

Enabling the module

  1. Return to your browser window. Go to the Module page at: http://YOURSITE.com/admin/build/modules.

    If you are not already logged into your Drupal site as an administrator, you will need to do so. Scroll down to the Views fieldset and enable the Views and the Views UI modules by clicking the two associated checkboxes.

  2. Click on the Save configuration button.

    Congratulations! You will now see a message (similar to the screenshot that follows), signaling the successful installation of our module.

Recipe notes

UI is an abbreviation for "User Interface". The Views UI module offers a point-and-click approach for selecting content and output types, controlling view sort order, and so on. The Views UI can even generate a views programming code for you, as we'll see in Chapter 2. If the Views UI module were not enabled, you could still see the existing views and create new views through code. However, the Views UI module is quite helpful: even "Ninja" Drupal programmers will typically enable it.

Command line tips

These shortcuts will assist you in your Drupal development (your host environment may, or may not, have all of these shortcuts enabled).

  • Press Ctrl+U in the command line to clear everything to the left of the cursor. For instance, if you paste something, and then realize the wrong text was in the clipboard, it may be easier to clear the whole line than to press backspace many times.

  • Press Ctrl+K on the command line to clear everything to the right of the cursor.

  • Press the up arrow to re-use a previous command line. You may also search your command history with Ctrl+R.

  • Type !$ on the command line to reuse the last argument of the previous command line. For example:

    more views_ui.module views.module
    

    lets you page through the text of both modules. The last argument of that command was views.module. If your next command is:

    less !$
    

    this will print as:

    less views.module
    

    (This tip is difficult to find with a search engine. A Google search for !$ yields nothing.) Quit both the more and less commands by typing:

    Q
    
  • Use "man" pages. Man is shorthand for the manual.

    man less
    

    reveals that

    Less is a program similar to more but which allows backward movement in the file as well as forward movement.

  • Type cd to go to your home directory.

    To return to the previous directory you were in, type:

    cd -
    
  • If you are not sure where you are in your directory structure, type:

    pwd
    

    This is the "print working directory" command, which provides the full path to your current directory. This is especially useful if your prompt is not set up to already display the full path.

  • Use the Tab key for command line completion. In step 6 of the recipe above, you could type:

    tar xvf v<tab>
    

    If there is only one file that begins with v in the directory, the Tab key will conveniently complete the full name of the zipped .tar file:

    tar xvf views-5.x-1.5.tar.gz
    

    Press Enter to run the command.

    If you already had the votingapi module installed, for instance, you would need to enter:

    tar xvf vo<tab>
    

    to distinguish voting from views.

Recipe 2: Views-related URLs on your site


Note

Ingredients

Administrative access to a Drupal web site and a printer

This is a quick tour of Views-related URLs on your site. Make yourself at home. Feel free to click around and generally become familiar with the Views interface.

  1. Administer Views: http://YOURSITE.com/admin/build/views

  2. Add a View: http://YOURSITE.com/admin/build/views/add

    (This is where we'll be spending much of our time in this book.)

  3. Import a View: http://YOURSITE.com/admin/build/views/import

  4. Views Tools: http://YOURSITE.com/admin/build/views/tools

  5. Views Help: http://YOURSITE.com/admin/help/views

  6. Views UI Help: http://YOURSITE.com/admin/help/views_ui

    (While you are on this page, go ahead and print it. This is an easy page to miss, but quite informative.)

  7. Views Permissions: http://YOURSITE.com/admin/user/access#module-views

    (We will interact with this page in Recipe 7.)

  8. Enable Views modules: http://YOURSITE.com/admin/build/modules

Recipe notes

  • If your site does not have the Clean URLs option Enabled, you will need to add ?q= before the URL parameters in the URL. For instance:

    http://YOURSITE.com/admin/build/views

    becomes:

    http://YOURSITE.com/?q=admin/build/views

Recipe 3: Creating a "Swim Groups" Page View


Note

Ingredients

Administrative access to a Drupal website

You may think of the Views UI as a series of questions. Here are some sample questions to consider:

  • What do I want to name this view?

  • What do I want to display?

  • Who should be able to view this content?

  • In what format should the content appear?

  • Do I want the content to appear in a page, or in a block (or both)?

  • How many items to display?

  • Is there any particular order (By date? Alphabetically?)

We will first need to create the content for our view.

Creating a new Content type (Swim Group), and adding content

  1. Go to Administer | Content management | Content Types. Select Add content type (http://YOURSITE.com/admin/content/types/add).

    If you have the Content Construction Kit (CCK) module installed, you will see more than two tab options, but as seen in the following screenshot, we simply have the Drupal 5 core, plus the Views modules that we have installed.

  2. Enter Name, Type, and Description.

  3. Keep the Submission form fieldset at default settings.

  4. In the Workflow fieldset, uncheck Promoted to front page and set the Default comment setting to Disabled.

  5. Save your new content type. You will see a list of your Content types, and a message that your new content type has been added.

  6. Go to Create Content | Swim Group, and add at least three content items (http://YOURSITE.com/node/add/swim-group).

Creating a View

  1. Go to Administer | Site Building | Views (http://YOURSITE.com/admin/build/views), and select Add.

  2. In the Basic Information fieldset, enter the following:

    • Name: swim_group

    • Description: List of swim groups

  3. Sections of the main Views UI form are contained in HTML fieldsets. Click on Page to open that fieldset if it is not already expanded. Note that when a fieldset is closed, a triangle icon points to the fieldset name (as seen in the following image); when the fieldset is expanded, the triangle icon points down. This is a subtle clue (available in most themes) to help you navigate the page.

  4. Enter the following values in their respective fields:

    • Provide Page View
    • URL: swim-groups

    • View Type: Full Nodes

    • Title: Swim Groups

    • Use Pager
    • Nodes per Page : 20

    In this section, we are essentially creating a new URL on the site, and displaying full content items (nodes). We are specifying that up to 20 items will be displayed on the page, and if we have more, we will have the option to see additional items on subsequent pages.

Selecting Filters

The following figure offers a visual representation of Views filtering. We see the multiple content types available on the site symbolized on the left (for instance, Page, Story, Swim Group). The filter allows only one content type to be displayed. In our case, we just want the Swim Group.

  1. Open the Filters fieldset. If you printed the Views UI Help, as suggested in Recipe 2, now is a good time to review the Filters options. There are many filter options available. We will select just two from the Add Filter drop-down list, Node: Type, and Node: Published. These are by far the two most commonly used filters. Select Node: Type from the drop-down, and click on Add Filter.

    The filter is added "above" the drop-down list.

    Select the Value as Swim Group and leave the Is One Of option of Operator, as shown in the following screenshot:

  2. Return to the Add Filter dropdown, and add the Node: Published filter. (As you add filters in Views, you may find that the interface hops back to the top of the page. If this happens, dutifully scroll back down to the Filters fieldset.) By default, when you add this filter, Node: Published Equals Yes. Leave the default as-is.

    Note

    If this filter is not added, the view will display items that are marked unpublished. This is an easy filter to forget, but it is recommended.

  3. You will now see a variety of Ops buttons. Note the Delete button. With a little imagination, you can see it looks like a trash can. Also, if you move the mouse over the button, the popup text, Delete this item appears. The delete button does not delete content from the site, it simply removes the filter. For instance, if you delete the Node: Published filter, the view would contain both published and unpublished content. The up and down buttons will prove most useful in the Sort and Field fieldsets, which we cover in Chapter 2. In Chapter 4, we will also cover exposed filters.
  4. Click on Save. When you first create a view, you are brought back to the "Views" List page. If you Edit your view from the view itself, you will be brought back to the view itself after editing it. Notice that the full URL of your view is http://YOURSITE.com/swim-groups. The message, View successfully saved, appears only the first time you view this. As an administrator, you will also see the Edit, Clone, and Export tabs. Those tabs are not displayed to site users who do not have Views administrative rights.

Recipe notes

It is worth highlighting some subtle distinctions in naming conventions.

  • Name: This is the unique identifier for a view. Hyphens are not allowed: use an underscore to separate multiple words.

    Compare the Name fields for adding content and adding a view. When creating a content type in Drupal 5 (Step 2, above), the first item on the page is the human-readable Name, while the machine-readable type appears second. The Views interface (Step 8) breaks this convention; the first item on the page is the machine-readable Name.

    Example:

    Machine-readable: swim_groups

    Human-readable: Swim Groups

    It is not a big problem if you misname a view (by including spaces, for instance). All of your careful settings will remain intact, and Drupal will simply issue the message: View name must be alphanumeric or underscores only, when you attempt to save your view. Edit the Name, and scroll back down to the bottom of the page to Save the Views form again. You are not required to use lower case in your Views Name, but it is a common and oft-preferred practice.

    It is acceptable for a machine-readable view name to be the same as the machine-readable content type. More typically, however, the content type will be singular, and the Views name plural. In our case, the content type is swim_group, and the view name is swim_groups.

  • URL: If you would like to use more than one word in a URL, use hyphens to separate them. This enables Google (and possibly to other search engines as well) to index them as separate words. Many developers use underscores, but hyphens have the edge when it comes to search engine optimization.

    Example:

    View Name: swim_groups

    View URL: swim-groups

    You may include slashes in the URL field. For instance: groups/swim.

  • Title: The title displays at the top of each page in the view. You may use some HTML markup such as <em>, <i>, and <b> to highlight phrases in the title. You may use a line break in a title <br />. You may also use HTML entities, such as &rarr; A helpful list of entity codes can be found at: http://www.w3schools.com/tags/ref_entities.asp. For the most part, however, formatting of the full title is handled in your theme (thus, you will not specify fonts or other styles on the Views page).

    Examples:

    <em>Swim</em> Groups

    Swim Groups: <br />Tadpoles, and Guppies, and Wrigglers, Oh My!

    Voil&agrave: Learn to swim at any age

    Compare Views Titles with Node Titles. HTML markup is allowed in View Titles, but not in Node Titles.

Recipe 4: Adding a Header to your View


Note

Ingredients

Completed Recipe 3

You can easily add custom text or graphics above or below your view content, using the Header and Footer fieldsets. We will add a brief description at the top of the Swim Groups page.

  1. Go to http://YOURSITE.com/admin/build/views. Your swim_groups view is now included in the list of views.

  2. Click on swim-groups in the URL column.

  3. Open the Page fieldset, and then open the Header fieldset contained within it.

    Enter the following header text:

    Swimming is a great sport which exercises the whole body. Swim lessons are available for all ages and ability levels. Note: A parent or guardian must accompany children under 5 when in the water.

  4. Open the Input format fieldset contained within the Header fieldset. Note that Filtered HTML is selected. See the Recipe notes if you would like to expand the list of available HTML tags.

  5. Scroll down to the bottom of the Edit view page, and click on Save.

  6. Enjoy the view.

Recipe notes

  • The Header fieldset (along with the Footer and Empty Text fieldsets) each contain Input format fieldsets. Input format filters will modify the display of text that has been entered by users (Input format filters are not connected to the filters fieldset that we described in Recipe 3). When a user enters text or code into a Drupal site, the text is saved in the database exactly as typed. Next time we view the text, however, it may not look exactly the same—some text and tags may not appear. To modify the list of allowed tags, visit the Site Configuration | Input Formats page, at: http://YOURSITE.com/admin/settings/filters.

  • The most common reason for using these filters is to protect your site from malicious users, or even from users who don't intend to be malicious but who exhibit bad form. The Input format ensures that scripts will not be run, and that badly formed HTML will not break your site's layout. Filtered HTML is the name of one of the default Input formats.

  • A terrific article by Robert Douglass offers helpful information on input filters at: http://www.lullabot.com/articles/drupal_input_formats_and_filters.

Recipe 5: Adding a View to a Menu


Note

Ingredients

Completed Recipe 3 or 4

  1. Edit the Swim Groups view, at: http://YOURSITE.com/admin/build/views/swim_groups/edit.

  2. Open the Menu fieldset, found within the Page fieldset. Check the Provide Menu option, and add a Menu Title.

  3. By default, the menu item appears in the Navigation menu. We don't want it here so we will move it in the next step.

  4. Go to Administer | Site Building | Menus.

    (http://YOURSITE.com/admin/build/menus).

  5. Use your browser to do a Find (usually Ctrl+F) for the word Swim. The first result will likely be in the actual sidebar menu item (if the Navigation menu has been placed in a region on the page). The second find will be the Swim Group content type listing in the menu configuration. The third one, finally, is the menu listing for the Swim Groups view. Click on the Edit link.

  6. The Path is already filled in, based on our settings from the Views UI (Step 2). Enter a Title, and change the Parent item to Primary Links. If you wish the menu items to appear in alphabetical order, you may leave the Weight for all items at 0. In our example, we'll set the weight to a negative number, ensuring that it appears early among the primary links.

  7. Your view is added to your Primary Links menu.

Recipe notes

Newly created swim groups are automatically added to the Swim Groups view, and its associated menu item.

Recipe 6: Creating a Block of Swim Groups


Note

Ingredients

Completed Recipe 3 or 4

In Recipe 3 , we created a page view, which is accessed via a URL. In this recipe, we are going to edit that view, adding a Block based on the same content. A view may provide both a Block and a Page view at the same time.

Blocks are placed inside regions made available by your theme. Sample regions that are common across most themes include the left sidebar, right sidebar, content top, and content bottom. A given block can appear on every page of the site, or just on pages that you designate. In the following steps you will create a Block for the Swim Groups view.

  1. Go to Administer | Site Building | Views

    http://YOURSITE.com/admin/build/views.

  2. Select the Edit link next to the swim_groups view.

  3. Open the Block fieldset, if it is not already open, and enter the following:

    • Provide Block
    • View Type: List View

    • Title: Swim Groups

    • Nodes per block: 10

    • [More] Link?
  4. Open the Fields fieldset, and add the Node:Title field. You may leave the various options at their default settings.

  5. Go to the Blocks page via Administer | Site Building | Blocks:

    http://YOURSITE.com/admin/build/block.

    Place the swim_groups block in the right sidebar (see the image below). Click on the Save blocks button at the bottom of the page.

  6. View your Block on any page of the site. The Block configuration page itself provides special formatting to inform administrators about various regions, so you may wish to view your block from a different page. For instance, click on the site logo, to go to the home page.

Recipe notes

It can sometimes be a bit disconcerting to have a single view create both a block and a page. The appearance may be different enough to be surprising. For instance, in our case, the block view contains a simple list of linked titles, while the page view contains the full text. The block had a maximum of 10 per page, while the page had a maximum of 20. You may optionally create separate views for blocks and pages. Consider naming the respective views block_swim_group, and page_swim_group, for instance. (Use separate views when filters, fields, or sort order differs between the page view and the block view. Otherwise, it's more maintainable to use one view for both blocks and pages.) Note that the Administer Views list keeps track for you, signaling that the swim_groups view has provided a Page, a Block, and a Menu item.

Recipe 7: Creating an "Admin" Role and setting Access Permissions


Note

Ingredients

Admin Role module: http://drupal.org/project/adminrole

When you first installed Drupal, the first user you created was, naturally, user #1, also known as the "super-administrator". If others users need administrative access to the site (to administer Views, for instance), it is a good practice to create a distinct admin role. The Admin Role module will save you the trouble of having to manually set permissions each time you install a new module. All new permissions will automatically be enabled for the admin role.

Installing the Admin Role module

  1. Go to http://drupal.org/project/adminrole.

  2. Download the Drupal 5 Admin Role module to:

    <DRUPALROOT>/sites/all/modules

    (Select the "tarball" marked Recommended for Drupal 5.)

  3. Unzip the module.

  4. In your browser, go to the Modules page at Administer | Site Building | Modules (http://YOURSITE.com/admin/build/modules). Scroll down to the Other fieldset, and enable the Admin Role module.

Adding an Admin Role

  1. Go to the Roles page at Administer | User Management | Roles (http://YOURSITE.com/admin/user/roles) and add an admin role.

Configuring the Admin Role module

  1. Go to the User management | Admin Role page at (http://YOURSITE.com/admin/user/adminrole) and select your newly created admin role from the drop-down list.

  2. Go to the User Management | Access Control page, and note that the admin(first column) already has the permissions set. These permissions were enabled by the Admin Role module.

Creating a User for the Admin Role

  1. Go to Administer | User Management | Users and select Add user.

  2. On the User account page for your new user, add a Username, E-mail address, and Password, and be sure to check the admin role.

Recipe notes

You will receive an Admin Permissions Set message at the top of the module page each time you enable a new module (some modules do not actually create new permissions, but you will receive this status message, nevertheless).

Recipe 8: Installing Firefox and Firebug


The rest of the recipes in this chapter are devoted to enabling you to see the full scope of the Views interface. This recipe is a prerequisite for Recipe 9, Revealing the full extent of Views. Firefox and Firebug are also useful in any web developer's toolkit.

Installing Firefox

Bring up your current browser, and go to http://www.mozilla.com/firefox. Click on the Free Download button. Follow the detailed directions for installing Firefox here:

http://support.mozilla.com/en-US/kb/Installing+Firefox.

Installing Firebug

  1. From Firefox, you can install Firebug by visiting Tools | Add-ons.

    You may also download the Firebug add-on from: https://addons.mozilla.org/en-US/firefox/addon/1843, or http://getfirebug.com/

  2. Go to the Get Add-ons tab, and click on Browse All Add-ons.

    This will bring you to the Firefox Add-ons page.

  3. Enter firebug in the search box. When the add-on description is returned, click on Add to Firefox.

  4. Click on Install Now.

  5. Restart Firefox to make the Firebug add-on available to the browser.

  6. Note the new Firebug icon at the bottom-right corner of your browser. Congratulations! You now have Firebug installed.

Recipe notes

Firefox Add-ons are also called "extensions". Many web developers say that if they could only install one Firefox extension, it would be Firebug. Consider spending some time at getfirebug.com to learn more about its features. For more in-depth discussion, join the Firebug discussion group at http://groups.google.com/group/firebug.

Recipe 9: Revealing the full extent of Views


Note

Ingredients

Completed Recipe 8

One reason that Views can feel a little bit mysterious, is that so much of it is concealed at first.

This recipe exposes all of the options on the main View's Edit screen by expanding all of the collapsed fieldsets on the page. This will save you the time it would take to manually open the nearly two-dozen fieldsets. The recipe uses a single line of jQuery. Please do not feel that you have to understand everything all at once when you see the full extent of Views! That's what the rest of this book is for. There is value, however, in the full array of options that will be available to you. A summary of the full screen can be found in Recipe 7. Note that fieldsets are nested within other fieldsets, up to three levels deep.

The list of all the fieldsets in the View's Edit screen is as follows:

  • Basic Information

  • Page

    • Header

      Input format

    • Footer

      Input Format

    • Empty Text

      Input format

    • Menu

      Default Menu Tab

  • Block

    • Header

      Input format

    • Footer

      Input format

    • Empty Text

      Input format

  • Fields

  • Arguments

    • Argument Handling Code

  • Filters

  • Exposed Filters

  • Sort Criteria

Ensure that Firefox and Firebug are installed (See Recipe 8)

  1. Go to admin/build/views/swim_groups/edit. If you have not yet created a view, go to admin/build/views, and click on Add.

  2. Click on the firebug icon in the Firefox status bar, or press F12 (on Apple laptops, it may be necessary to hold down "Fn" while pressing F12). If you get a message regarding the need to enable Firebug for the site, go ahead and do that. Firebug opens at the bottom of the browser.
  3. Click on the Console tab in Firebug. An understated JavaScript (and jQuery) command line appears in the lower left, after the >>> prompt. You may notice the blinking cursor.

Running the jQuery command

  1. In the command line area, enter the following jQuery command. Make sure to include the dollar sign character.

    $('fieldset').removeClass('collapsed')

  2. The full scope of the views Add or Edit interface appears in the browser. Take some time to explore the page.

Recipe notes

How does this recipe work? If the jQuery command above were to be read as English, it would say: "Find all of the fieldsets on the page, and remove the collapsed CSS class from all of them". The effect is to open all the fieldsets (JavaScript must be enabled for this to work).

Let's elucidate this further:

  • The HTML fieldset tag in most Drupal themes (including the default Garland theme) looks like this, when collapsed: <fieldset class="collapsible collapsed">

  • An expanded tag looks like this in HTML:

    <fieldset class="collapsible">

The jQuery code removes all of the "collapsed" classes from the Views page. Thus, all the fieldsets are open, revealing their full contents.

Most of the time, you will not want to interact with Views in this expanded way, but it certainly is helpful, sometimes. It's nice to know that Firebug CSS edits are temporary. The next time you view the page, the fieldsets will refresh with their default open or closed appearance. Press F5 in Firefox to refresh the page you are on.

Note

This jQuery fieldset expansion command does not function if you have already manually closed a fieldset with your mouse.

Recipe 10: Preparing Views Worksheets


Note

Ingredients

The Views Worksheet in this chapter

Copy machine

Pen or highlight markers

On the following page is worksheet that lists each element on the View's Add or Edit form. This worksheet will serve as your guide as you learn the features of Views.

  1. You have permission to photocopy the Views Worksheet. Start with a dozen copies or so. You may choose to copy more or less depending on whether you think this resource suits your learning style.

  2. Edit the Swim Groups view that you created in Recipe 3 http://YOURSITE.com/admin/build/views/swim_groups/edit.

  3. On a worksheet copy, mark each element used by the view (use a pen, or highlight markers according to your preference).

Recipe notes

The worksheet divides elements into four categories: Text, Checkboxes, Dropdowns, and Radio Buttons.

  • Some text boxes expect numeric characters, as noted in parentheses.

  • Checkboxes can be considered as a yes or no question. For instance: Provide Page View is the Views shorthand for "Do you want to provide a page view?"

  • Some of the drop-down boxes allow you to select more than one element.

  • Radio buttons are mutually exclusive.

Summary


In Chapter 1, we installed Views, took a whirlwind tour of associated URLs, and then created our first view: a list of Swim Groups. We edited the page view to add header text and then created a menu link. We then produced a block that could be added to any page. We had a chance to see the full scope of the Views interface in two ways: first, using a jQuery command to expand all fieldsets, and second, using a summary worksheet of all the Views Edit options. Worksheet copies will continue to be a useful resource throughout the rest of the book.

Left arrow icon Right arrow icon

Key benefits

  • Display particular types of content in unique and compelling ways on your Drupal web site
  • Enhance your web site with calendars, timelines, galleries, maps, podcasts, Views Fusion, and more
  • Indispensable resources for Drupal 5 Administrators ñ Drupal Administration Menu, Views Bulk Operations, ModuleInfo, and Editable Fields modules
  • More than 90 recipes ñ pick the ones that work best for your web site

Description

The Drupal View modules give you flexibility and freedom to customize the display of your web site's content. Although there are more than 100 views-enabled modules, few site administrators use Drupal Views to its full potential. This book will enable you to realize the fullest potential of this powerful resource by providing a wide variety of powerful recipes for creating and displaying a wide variety of views ñ essential classics you will use again and again to innovative display methods that will make your Drupal site stand out. Pick and choose the ones you would like to prepare for your web site. In this book you will find ninety-four recipes to create a wide selection of views. The list includes event listings, interactive calendars and timelines, maps, proximity search, podcasting, carousels, Views Fusion, and many more. You will also explore default views, views with CCK, and master a variety of ways to associate views with related content. Most people think of Views for site visitors. But Views can also be handy for site administrators. You will get to know the Views Bulk Operations module, along with Editable Fields, and Views Custom Fields. (You'll probably wonder why you never used them before!) If you want to take Views to the next level, the book contains a code-rich chapter on theming. However, you will find most of the recipes detailed by the author do not require any original coding at all. As you progress through the recipes, you will be immersed in such Drupal Views topics as fields, arguments, filters, exposed filters, sorting, style plug-ins, formatters, cloning and copying views. Because Drupal is a worldwide and ever adapting system, the author also includes great tips and resources for navigating the online Drupal community and expanding your knowledge of the recipes. Finally, there is an extensive Appendix, which includes listings of all default views, formatters and style plug-ins for Drupal 5, along with a categorized list of patches.

Who is this book for?

This book is primarily written for Drupal site builders, administrators, and themers who want to develop custom content displays using Views. It can be used by anyone who has a Drupal 5 web site, including original site developers as well as people who have inherited a Drupal 5 site. Some knowledge of HTML and CSS is required; PHP basics will be handy for some of the recipes.

What you will learn

  • Master the Views User Interface
  • Create views arguments
  • Implement and create default views for recent comments, the frontpage, group listings, and more
  • Explore a variety of ways to associate views with related content
  • Display event listings, calendars, and timelines
  • Make site administration easier using several administration modules
  • Enhance your web site with Google Map tools, YouTube video bar, photo gallery, audio, and Views Fast Search
  • Enable your users to flag and bookmark content for later viewing
  • Incorporate views into panels and tabs
  • Create a directory of available theme functions, and learn some key debugging strategies
  • Use theme overrides and CSS to create more attractive views
  • Fix the long-standing taxonomy term bug, and the body field Views display issue
  • Create and apply patches
  • Create some helpful browser buttons and search plug-ins to facilitate finding information online
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 27, 2009
Length: 412 pages
Edition : 1st
Language : English
ISBN-13 : 9781847196965
Languages :
Concepts :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Publication date : May 27, 2009
Length: 412 pages
Edition : 1st
Language : English
ISBN-13 : 9781847196965
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 152.97
Drupal 6 Theming Cookbook
$48.99
Drupal 7 Social Networking
$48.99
Drupal 5 Views Recipes
$54.99
Total $ 152.97 Stars icon
Banner background image

Table of Contents

8 Chapters
Introduction to Views Chevron down icon Chevron up icon
Working with Default Views Chevron down icon Chevron up icon
CCK and Views Chevron down icon Chevron up icon
Dates and Calendars Chevron down icon Chevron up icon
Views and Tools for Administrators Chevron down icon Chevron up icon
Views Galore Chevron down icon Chevron up icon
Theming and Layout Chevron down icon Chevron up icon
Navigating the Online Drupal Community Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(3 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Daniel Hanold Oct 28, 2009
Full star icon Full star icon Full star icon Full star icon Full star icon 5
One of the main reasons I was pleasantly surprised about Drupal 5 Views Recipes was the fact that the book doesn't just give a laundry list of views (or recipes), but instead helps the reader understand Views from a conceptual perspective. Personally, I much prefer a book that explains a concept as it allows me to not just execute an example that's mentioned, but transfer my knowledge to my individual requirements.This book delivers a great overview about Views without being overwhelming and starts out with a very simple view that gets fully dissected and explained. It then moves on to explaining working with default views (which come shipped with the Views module) as a basis for a site's custom views. Views learning curve is especially steep when trying to use taxonomy terms. Drupal 5 Views Recipies describes all the GOTCHA's and ways to get around them, such as an excellent description on displaying all terms from a specific taxonomy and using Drupal's "l" function to create the related links.Views' right hand (well, they're pretty much equal partners) is the Content Construction Kit, or CCK, which allows the definition of custom fields for content types. Drupal 5 Views Recipes explains very well how to combine the two modules effortlessly and create views such as a blogroll, using the CCK link field. Another rather complex module is CCK's Node Reference field, which requires the usage of arguments in Views. Again, the best way to conceptually understand the interaction between the two is a simple example, exactly as the one used by the author. Furhermore, the book explains how to use dates in Views. Both the Date module itself as well as large number of other module gems are explained in the book, such as setting up a calendar block, visually showing aggregated data using the Timeline module and the setup of a summary view, which can be used for things like "blog posts per month", aggregating the number of posts in a given month.Since working with the Views module requires dealing with a lot of different aspects of Drupal (content types, users, taxonomy, many different types of CCK fields), I was excited to get much more than just information about Views out of this book. Drupal 5 Views Recipes contains a lot of the "bread & butter" developer knowledge required for every Drupal admin, ranging from dealing with Firebug, how to work with cron and some basic understanding of the UNIX command line. Theming of views results is also mentioned in the book, although it only touches the surface. Also, this are of the book is not applicable to Drupal 6 / Views 2, as theming is the one area that radically changed in Views 2.Overall, I can highly recommend this book to any Drupal administrator looking to begin working with Views or trying to become a Views expert. I was somewhat sceptical about the fact that this book focuses on Views 1 / Drupal 5 only. Conceptually however, there are no big differences between Views 1 and 2, so I would also recommend this book for Views 2 beginners using Drupal 6. I my view, the documentation that comes with Views is very brief and technical, and I am excited that the author succeeded in explaining the concept of Views in a structured and easy-to-comprehend way. I'll be the first to buy the second edition with an update to Views 2.
Amazon Verified review Amazon
Another Drupal fan Jul 09, 2009
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I am not a PHP expert and I barely know how to spell CSS. My first attempt at website development began three years ago with the decision to utilize Drupal. After three years of trial and error, the searching of forums, posting questions, hiring four different developers, installation and then un-installation of almost one hundred modules, and the purchasing of several reference books and videos, I would say that I still have barely scratched the surface of potential with Drupal.So it seems to me that there are basically six levels or stages of Drupal knowledge and understanding that users (other than true professional developers) go through:1. The Discovery phase where the user decides "This looks easy, how hard can it be to plug in a module?"2. The Awakening phase where the user finds that Drupal is amazingly powerful.... with hundreds of ways to attempt to solve the problem and to really tweak their website, they must use and understand modules and possibly the basics of CSS. This is the stage where the user may even abandon Drupal due to the feeling of being overwhelmed.3. The Acceptance phase where the user decides they if they want to really customize their site they may need to seek professional help.4. The Disbelief phase where the user discovers that anyone with a computer can claim to be a Drupal expert and that they (the user) may in fact know as much as the Pro they have hired. This user is not afraid to wade into the fray, comfortable in the knowledge that the site can always be restored from a backup (you DID backup the site didn't you?).5. The Semi-Pro - Feels comfortable with about 90% of the requirements for building an awesome website, but still discovers new ideas and processes through forums and books6. The Pro - only occasionally needs help with the finer details of a particular code snippet or module customization, generally can figure it out without assistanceWith these phases in mind, I would say that "Drupal 5 Views Recipes" is a fantastic resource for stages 1 through 5. Certainly some users within the different stages will gain more from the book than will others, but overall this is a cookbook with recipes designed to not only attain a particular result... but also to help remove the "tunnel vision" thought process for solving Drupal problems.This book includes almost 100 "recipes" with specific examples of how to set up the modules to attain a particular result, plus the downloadable files enable copy and paste simplicity.Topics/Recipes include, setting up the Frontpage, podcasting, Google proximity views, Blogrolls, tweaking themes, displaying charts, Photo Galleries, YouTube, Calendars, Popular Content pages, exposed filters, applying and creating patches, setting up Cron, a thorough discussion with examples for VBO (Views Bulk Operations), Google maps, formatting of queries, Panels, code snippets to tweak the PHP files, etc.Though written for Drupal version 5, many of the workflows and module combinations will work equally as well in version 6 (although the user interface in v6 may be different in some cases).As I mentioned earlier..when it comes to site development in general and specifically Drupal, I am NOT a Pro. I need instructions as well as a "Step One, Step Two, Step Three approach and that is what I really like about Marjorie's approach.This will become a well-worn reference guide in my library of Drupal tools....I highly recommend it!
Amazon Verified review Amazon
AmySuzanneJ Oct 25, 2009
Full star icon Full star icon Full star icon Full star icon Full star icon 5
While this book is very helpful for understanding views and the many things that can be done with them, it covers much more than just that. It provides a good understanding of Drupal for the person who is just stepping out of the novice category of Drupal users. It gives tips on customizing the administration page for easier usability, how to utilize the [...] website to maximize its usefulness as a source of information, and it provides a listing of useful Drupal modules. There is also a list of online resources for getting more information about Drupal.I hesitated buying this book because it specifies that it is for version 5 of Drupal right on the cover. I finally bought it because I wanted a better understanding of views, and I have been quite happy with my purchase ever since. Yes, there are some things specific to Drupal 5, but it is generally pretty quick to figure out the differences for Drupal 6. I'm sure I will keep coming back to this book for ideas for quite awhile.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela