Blocks are smaller chunks of content that you can place in your pages. Examples of some default blocks provided are "Who's online," which shows a listing of users currently logged in; the "User login" block, which displays a login form to anonymous users; and "Recent comments," which shows a list of the newest comments on the site. Even the Navigation menu and "Powered by Drupal" button in the footer shown in Figure 2-8 are blocks! You can also make your own custom blocks: for example, you might create a block to display an announcement about an upcoming event.

Figure 2-9 shows the block administration page at AdministersSite buildings-Blocks (admin/build/block). Blocks are placed within a region of a page. Examples of regions are "left sidebar," "footer," and "content." Region names, and exactly where they appear on a page, can vary from theme to theme; some may define additional regions such as "Banner ad" or remove or change some of the default regions. Therefore, blocks must be configured on a per-theme basis. We'll discuss more about regions later in the "Spotlight: Themes" part of this chapter when we talk about themes. As with menus, the handles here may be used to drag blocks to different regions.

Figure 2-9. Block administration page

Be careful with using and giving access to use PHP on a Drupal site. Although an extremely powerful tool, the ability to work with PHP within a web application like Drupal opens the door for security problems and site crashes. We'll harp on this point again later in the "Hands-On: Configuring Permissions" section when we talk about access permissions.

You can customize the visibility of blocks, as well: for example, to show blocks on only certain pages or only to users with certain roles. You may also optionally use PHP to specify complex visibility settings—for example, to display a "Help" block to any users who have been members for less than a week. There is also an option to let users control the visibility of certain blocks themselves, so they have more control over their browsing experience.

One frequently asked question is how blocks and nodes differ, as both display content. One general rule of thumb is that blocks are typically supplementary information to the actual content on the page. Blocks' content is also usually either constantly changing (in the case of the "Who's online" block), or consists of temporary information such as a blurb that's displayed on the front page for a few days. Block content is not searchable, so if the content needs to be referenced permanently, a node is a much better choice.

Was this article helpful?

0 0

Post a comment