Book Image

Drupal 5 Views Recipes

Book Image

Drupal 5 Views Recipes

Overview of this book

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.
Table of Contents (22 chapters)
Drupal 5 Views Recipes
Credits
About the Author
Acknowledgement
About the Reviewer
Preface
Default Views in Drupal 5 Modules
Formatters
Style Plugins
Views Hooks for Coders
Modules Included in Recipe Ingredients
Additional Resources and Modules Mentioned in Recipes
Selected Noteworthy Patches to Views
Index

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.