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.
Go to Administer | Site Building | Views
http://YOURSITE.com/admin/build/views
.Select the Edit link next to the swim_groups view.
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?
Open the Fields fieldset, and add the Node:Title field. You may leave the various options at their default settings.
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.
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.