Drupal Blocks

Official Drupal documentation on Blocks:
Working with blocks http://drupal.org/documentation/modules/block
Restricting blocks to certain pages http://drupal.org/node/21870

We have already discussed the foundation of content management in Drupal - fields that combine into content types and nodes that are instances of content types, and the fact that Drupal's power comes from the ability to create custom content types. Nodes provide the main content of each page; but there are other interface elements wrapped around them. Each page has a header with the site's name and logo; there is also usually a navigation menu and an administration menu.

Block administration page in Drupal 7: Editing block settings for the Bartik theme. The system path is /admin/structure/block

Blocks provide still another possibility to enrich page content. They are usually smaller panels, snippets of content that can be displayed alongside nodes, which provide the main content. For example, a block may contain a search box displayed in a side bar on a page that shows a product catalog. Blocks can contain additional navigation menus, lists of recent content, images, contact information, weather forecast widgets, clocks, list of online users, external news feeds - the possibilities are endless.

One important thing about blocks is that they are theme-specific. If you have more than one enabled theme, a block enabled and placed in a header of one theme will not appear in another theme unless it is enabled there as well. This is useful because it allows to use two themes - one for the readers, and one for the administrators - and display different content to the two groups. It can be also frustrating if you forget to check what theme you are working on while enabling blocks.

Drupal 7 comes with a set of pre-manufactured blocks. They can be dynamic lists (recent content, recent comments) or just static elements holding snippets of HTML (like the "Powered by Drupal" block, which does nothing other than displaying that statement and providing a link to drupal.org). Just like themes and modules, these blocks must be enabled to become functional; when they are disabled, they are stored on the server but are not displayed.

Besides the pre-manufactured blocks, you can create additional custom blocks. In class, we created a block called "About Us" that contained some information about the site. Just like with nodes, you can use HTML when writing block content. This gives you a lot of possibilities (such as the ability to embed audio, video, and image files).

Another way to get new blocks is to enable new modules. For example, once you enable the Aggregator module, you can make blocks out of external RSS feeds. The Planet Drupal feed on our front page is made that way.

Finally, blocks can be used as a layout tool thanks to the ability to filter their visibility by node type, page, and user role. For example, you can enable a search block but restrict its use to authenticated users and administrators. You may decide to show the "About Us" block on the site's home page but not anywhere else. Each time you publish a block, you can display a block that shows five previous blog entries; but you don't need to show that on Article node pages ("blog" and "article" being different content types).

Controlling block visibility in Drupal 7: Making a block appear only on the home page. To edit visibility settings, go to the Blocks administration page (system path: /admin/structure/block), then click "Configure" next to the block you would like to edit; scroll down to the visibility settings