Blocks & Context: Placing Menus & Misc. Elements

(Image of blocks)Nodes (e.g. pages) consist of content & taxonomy fields, but if you want to place content across a set of nodes in a certain area of the ALA theme, like a sidebar, you need to use the Drupal Blocks system. Blocks are bits of content, sometimes module generated, that can be placed independently of nodes.

Going to Structure --> Blocks will reveal all the blocks currently in the system.

Types of Blocks

  1. Blocks: Custom, hand-made blocks. To create one, click in the Blocks UI.
  2. Blocks generated by modules: There are numerous systems (modules) installed into Drupal, and many generate their own blocks automatically. These usually cannot be edited directly through the Blocks UI.
    • Blocks generated by menus: This is an example of a module-generated block. Every menu you create in the Menu UI (Structure --> Menus), the Menu module will also create a block, allowing you to place the menu on your website.

Placing Blocks Through the Blocks UI

This is the interface you'll use for editing or creating blocks.

Block editing page showing Block Description and Block Body fields

The notable areas are Region Settings and Show block on specific pages.

Region Settings

While the ALA theme has many "regions" where blocks can theoretically be placed, practically speaking there are only a few to use:

  1. First Sidebar (the left-most column)
  2. Above Content (appears above the node in the center content column)
  3. Below Content
  4. Second Sidebar (the right-most column, which is only shown when a block is placed there.)

Show Blocks on Specific Pages

This is where you'll set which URLs the block will appear. If you're working on the PLA site, and you want your block to appear on ala.org/pla/test for example, select Only on the listed pages, and in the box, enter: test

The asterisk wildcard works (e.g. test/*) but exclusions do not. If you need greater flexibility in block placement, use the Context UI instead.

Placing Blocks Through the Context UI

conditions and reactions in the Drupal block creation set-up

A certain level of permission may be required to enter the Context interface. Launching the Context interface (Structure --> Context) will present you with a list of preexisting "contexts". Where the Blocks UI worked on individual blocks, a "context " is a more generalized set of conditions and reactions. Going back to the PLA example, you could make a similar "context" with the condition of the "path" being test, and a reaction of placing your block in a certain region of the ALA theme. Such a context would look like the image on the right.

Once again, the condition is "Path", and the reaction is "Blocks". With the "Path" text box, you can include multiple paths, and also exclude paths by prepending a line with a tilde (~). There are lesser-used conditions available, such as the "role" (permission level) of the user, the taxonomy of the node, etc.

It's also possible to add multiple blocks, whole stacks of blocks even, with a single context. Context is often used on ALA to place certain site-wide theme elements, place or swap the left nav, and fill special pages & site areas with custom blocks.

Reordering Blocks

If a path contains several blocks in the same region, with some placed by the Context UI and others placed by Blocks UI, you may encounter difficulty ordering them in a specific way. To resolve this, make sure to click "Show row weights" in both interfaces and assign numerical weight values. The weight values of one interface will respect the values of the other interface.