Hour 19. Using Blocks

What You’ll Learn in This Hour:

• Understand the Basics of Using Blocks

• Create Blocks

• Place Blocks on Your Pages

Introduction

This hour explores a major component of Drupal—the blocks that can appear in various regions of your site’s pages. Figure 19.1 shows part of the front page of the author’s site (northcountryconsulting.com). Nothing about it indicates that it is a Drupal site. In fact, the layout of the page could be created with any number of sitebuilding tools, including hand-crafted HTML.

Figure 19.1. Use blocks to display information in specific page regions.

image

What you cannot see are some of the Drupal features that are built in to the block structure. As is so often the case with Drupal, it takes care of many of the issues that you would have to manage with scripts or carefully structured HTML. In this hour, you will see how to create your own blocks and use blocks that are provided as part of Drupal or contributed modules. You learn how to use options so that blocks are or are not displayed under various circumstances, and you learn how to arrange and rearrange the blocks on your pages.

Introducing Blocks

The center of the page shows blog entries, but the left and right margins contain blocks. Each Drupal theme can define its own regions for blocks; the standard ones are left, right, header, footer, and content. Many themes define additional blocks. If you change a theme, you may have a little rearranging to do, but your blocks should work properly in their new locations.

In Figure 19.1, you can see blog entries in the center content section. The left and right regions contain blocks. Starting in the upper left, these are the blocks:

User Login— Standard Drupal block. If a user is logged in, it does not appear. (You do not even have to click a check box for this behavior.)

Downloads— Below User Login is a Downloads block. You can create a block of your own with a title and text. Figure 19.2 shows how the Downloads block is specified. You give it a name, a title, and its text. If you want to be sophisticated, you can limit its visibility. In this case, the block is shown only to anonymous (non-logged-in) users. A companion block is shown to authenticated (logged-in) users; it contains download instructions.

Figure 19.2. Create a simple text-only block.

image

Poll— Provided by the Poll module that is part of Drupal.

Search— Also a Drupal block.

Contact Jesse— Like Downloads, this is a user-created block. Unlike Downloads, it is not just text; it is HTML that provides links to a site-wide contact form as well as to a Webform.

Books— A user-created block that contains HTML. The difference here is that the HTML was generated by Amazon.com and contains links to its associate’s site.

As you can see, blocks have relatively few limitations, particularly because if all else fails, you can write HTML code. You will find a variety of blocks in Drupal and its contributed modules. Functionally, blocks fall into several categories:

Basic functionality— These Drupal-provided blocks implement log in, search, and so forth. Primary and secondary links, as well as menus, are in this category; they are discussed in Hour 21, “Working with Menus.”

Dynamic blocks— Automatically updated by Drupal. They can provide up-to-date and changing information to your users with no effort on your part other than placing the block. Example are New Forum Topics, Active Forum Topics, Archive List, Recent Blog Posts, Recent Comments, Latest Image, Random Image, Popular Content, and Who’s New.

Your own blocks— Whether plain text or HTML, you can do whatever you want in your own blocks.

View blocks— As you saw in Hour 14, “Working with Views,” you can create various types of displays for your views. One of those displays is a block display. This means that you can create your own block from a view and display your own data.

Contributed module blocks— This is an area of great interest to the Drupal community, and the offerings are growing rapidly. The Simplenews contributed module which is used to construct newsletters in Hour 12, “Using Blogs and Newsletters” installs a block that people can use to sign up for newslettters, for example.

“Search the modules pages for the keyword “advertising” to see some powerful, useful, and even profitable blocks and modules.

Creating and Using Blocks

You have seen the basic components and features of blocks. The way to master their use is to actually start to use them.

Summary

Blocks help provide a look-and-feel to your site. Because blocks appear in the same general place on all pages on which they are shown, they provide anchors to the content on the pages.

You cannot work with blocks effectively unless you work with themes at the same time. It is a matter of taste, as well as of your website’s purpose, whether you want a lot of blocks in a lot of regions or a few blocks in a few regions. Fashions of web pages come and go; there are ardent proponents of a single sidebar design (in Drupal terms, all blocks at the left or right of the page). In general, regions of a page collapse if nothing is in them, so you can have cluttered pages for webmasters and administrators and sparse and elegant pages for your authenticated users.

Q&A

Q. My HTML in a block does not work. Is there a simple solution?

A. Make sure that you are using the Full HTML input format.

Q. If a user falls into several roles, which role determines visibility of a block?

A. Permissions in Drupal are positive. That means that you specify that a certain role can do something (view, edit, delete, and so on). You never specify a negative—that someone cannot do something. Thus, if any role allows a user to see a block, that is what is applied. It cannot conflict with another role, because other roles are silent on access, rather than blocking access.

Workshop

Quiz

1. How long can a block’s text or HTML code be?

2. What determines the top-to-bottom order of blocks?

3. How do I change the module title?

Quiz Answers

1. There is no real limit, but if it is too lengthy, it may distort the page.

2. Drag them up and down in the block list using the four-way arrows. Remember to save the new order with the Save Blocks button before continuing with configuration.

3. Enter a new title, leave it blank to use the default, or use <none> for no title.

Activities

The number of combinations and permutations of blocks, roles, pages, and visibility quickly becomes enormous and unmanageable. Using pencil and paper (or a white board), draw the basic page design for your pages. Then, assign subregions for each block you intend to use. Annotate the subregion with the modules it will contain and their conditions. Having a consistent layout makes your site easier to use.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.214.32