Working with Blocks

Blocks are the chunks of text or information that appear around the page – typically in columns or "sidebars" on the right or left, but depending on your site's Theme, they could appear at top, at bottom, anywhere and everywhere.

Drupal provides many ready-to-use blocks with useful information, such as links to popular content; you can create your own blocks as well.

The Blocks administration form

There's a handy form for working with blocks:

Navigation menu » Administer » Site building » Blocks

Regions and block arrangement

The Blocks form automatically shows you something that other pages don't: the location on your site of regions. You'll see colored spaces scattered about the pages, with names like "left sidebar", "right sidebar", "sidebar last", "content top", "footer", and so on – maybe some of those exact names, maybe not, but probably a few along those lines.

Regions are where you place blocks. The exact regions you'll see, and their locations, are determined by the Theme chosen for your site. Regions are one of the key considerations in choosing a Theme for your site: You'll want a Theme that includes regions in the locations where you want to place blocks.

Can a region hold more than one block? Sure! Toss as many into a region as you like. The only real restriction is on what'll fit in a region and still look good. A number of blocks could fit nicely into a sidebar, stacked one on top of another; it's a common look on web sites. Multiple blocks in a region at the top of the page, though, could push all of your main content way, way down the page – not a good look. 

Similarly, a block containing a short, wide image might look great at the top or bottom of the page, but really screw up layout (or appear cut-off) if placed into a sidebar region. Some blocks will contain lots of stuff, and others won't. Fitting blocks of varied shape and number into your site's regions is a bit like working a puzzle. Experiment freely with block placement until things fit nicely.

List of blocks

At the top of the Blocks form, you'll see tabs for 'List' and 'Add Block'. List is what lets us lay out blocks on the page, so let's look at that.

Immediately below List, you may see several links representing various graphic Themes your site is equipped to use, allowing you to set different block configurations for each Theme. There's no need to worry about it now; by default, the Theme you're currently using should be selected, meaning you should have no problem seeing the changes you make to blocks. 

Elsewhere near the top of the form you should see some built-in, brief instructions on administering blocks.

Below all that is the meat of the form: the list of blocks available for your site (though most of them likely aren't actually appearing on pages). The blocks appear on the list grouped by region – or, for blocks that haven't yet been assigned to any region (and thus which don't appear on pages), under the group 'Disabled'.

Blocks are listed with the following columns of information:

Block

The description of the block. (Not all of the descriptions are necessarily easy to understand...) You can also think of this as the block's name that this form uses (but which may not be the same as the title that actually appears on site pages). 

Region

As described above, regions are the locations on the page, set by your site's Theme, where blocks can appear. You can set a block's region freely. For any specific block, just take a look at the regions displayed here and there on the Blocks form, decide which of those should contain the block, and select that region from the pop-up menu. Click the 'Save Blocks' button below the list, and boom, there's your block. (If you don't see the block right away, it may be set up to appear only on some pages, or only for some users. See Configuring Blocks below.)

If region is set to "<none>", the block's name will place itself under the 'Disabled' portion of the list, and the block itself won't appear on pages. That's how you "turn off" a block.

How do you order blocks within the same region? In Drupal 6, each block on the list has a cross-shaped "handle" in front of it; just drag that move a block up or down (or even move it to a different region!). The order in which blocks appear in a region is the order in which they'll appear on pages. 

Weight (Drupal 5)

In Drupal 5, you can't order blocks within a region by dragging them as above. Rather, you freely assign each block a weight, from -10 to 10. "Lighter" weights (lower numbers, including negative numbers) will "rise" to the top; "heavier" weights (higher numbers) will sink to the bottom.

For example, you give the "User login" block a weight of 1, and the "Recent popular content" block a weight of -2. You set both to appear in the left sidebar region. "Recent popular content" has the "lighter" number, and so will appear higher up; "User login" has the "heavier" number and so will appear underneath.

If two or more blocks appearing in the same region have equal weight, they will appear in alphabetical order of their titles.

Throttle

If your site uses the Throttle module, your block form will have a check box with this name. If you check the box, then your site will turn off the block – "throttle" it – when your site comes under a heavy load. Crowds of visitors can slow down your site, resulting in some frustrated guests; the throttle checkbox will turn off unimportant blocks under those conditions, to help keep your site fast.

It's an interesting feature, but there's no need to worry about it until your site is in the envious position of having to engage in crowd control.

Operations

Here we have the links to configure details of specific blocks, or even delete blocks you've made yourself. (You can't delete key blocks that are provided by Drupal; you can turn them off by setting their region to "<none>", which is just as good.) Read on for details of configuration.

Configuring blocks

Click 'configure' in a block's Operations column to set details of how it appears or functions. The options available to you may vary by block, but here are the key options common to all blocks: the block's title, and a handful of settings that determine when the block does or doesn't appear on your site.

Set your options as below, then click 'Save block' at the bottom of the form.

Block specific settings

Block title

This is separate from the block description. The block's description is what appears in the block form's list of blocks; the block's title is what appears to web site visitors. You can freely change the block title, or even leave it blank.

User specific visibility settings

Custom visibility settings

Can users decide whether or not to turn the block on and off? Typically, you won't be concerned about that; set the block to 'Users cannot control whether or not they see the block', and be done with it.

The other two options do give users the option to turn the block on or off – but it's an option only for logged-in users, not anonymous visitors.

Role specific visibility settings

Show block for specific roles

If you leave these check boxes blank, the block will be visible to all users. Otherwise, it will only be visible to the selected roles.

User roles are a topic for later. For now, you might want to make a simple choice among these three options:

a) Make block visible to everyone: Leave all roles unchecked.

b) Make block visible to administrators and other registered users, but not anonymous site visitors: Check all roles except 'anonymous user'. (This is useful for administrative and other "private" blocks.)

c ) Make block visible to anonymous site visitors, but not administrators and other registered users: Check only 'anonymous user'. (This is useful for any information blocks that you want visitors to see, but that just get in the way for you once you're logged in. Advertisement blocks would be a good example.)

Page specific visibility settings

Show block on specific pages

Similar to how the above settings can show the block only to specific user roles, these settings can show the block only on specific pages. Limit yourself to either of the first two options:

a) Show on every page except the listed pages. If you leave this blank, the block will appear on any page. If you input, for example, about, the block will appear on any page but the page <your site domain>/about.

b) Show only on the listed pages. If you leave this blank, the block will appear on no page, so be careful! If you input, for example, taxonomy/term/1/, the block will appear only on the page <your site domain>/taxonomy/term/1/.

A few added tricks and tweaks:

Under either of the above two options, you can specify multiple pages. Just hit return after each page, entering one page per line.

Note the special instruction that appears under the 'Pages' field: To specify your site's front page, use the special input <front>.

Users with a little computer savvy can use the * wildcard character. For example, taxonomy/* would specify any page that began with taxonomy/, whether taxonomy/term, taxonomy/term/1/, taxonomy/term/25/, etc.

Adding blocks

At the top of the block form, next to the 'Lists' tab, is a tab for 'Add block'.

The resulting form is simple, with only three items to input:

Block description

Input a short descriptive name or sentence. This will identify the block on the block form's list of blocks.

Block title

Inout the title that will appear at the top of the block on web pages. This could be something boringly descriptive ("Recent news") or something more exciting ("ATTENTION!"). You can also leave it blank, in which case the content of the block will appear unadorned by a title at top. 

Block body

This is the block content that a site visitor will see. Good ideas for content in a custom block include company contact information, a favorite quote, or a special announcement.

Configuring your new block

After you've input the above items on your new block, click 'Save block'. Your browser will go back to the 'List' tab of the Blocks administration form, and you'll find your new block somewhere on the list under Disabled.

You can now set your new block's region and its order within the region, as described above. You may also want to configure it, as described above. It's a little inconvenient, but Drupal doesn't let you set all of the configuration options at the same time you create the block; you have to create it as the first step, then configure it as the second step.

A final note: On the Blocks form, you'll also see the option to delete your new block, should you for some reason not be enamored with your creation. 

Comments

Gavin Doolan's picture

Not sure if its possible to display blocks in different regions on different pages?

One issue I have is in relation to the forum pages.

I can display say (online users) on the forum page, but the comments part of it becomes /content/ etc... that means its very difficult to exclude it or include it on those pages even though they are part of the forum pages.

Not sure if there is a work around for this or not.

drupalace's picture

I looked into that once, and did not find any easy way to make a block appear in different regions on different pages.

Another thing I've wished for: the ability to use more detailed conditions for a block appearing in the first place, such as "appear on all pages with path forums/*, except for forums/main".

Hmm, combine both of those, and that'd be pretty wonderful: a bit of conditional logic for each block, that would let you set its appearance, its region, and its weight, based on conditions. I wouldn't be surprised if Drupal gains that ability some day!

Gavin Doolan's picture

Seems silly that it doesn't allow it really. Since its so flexible.

Ideally you should be able to control where blocks are output and how they are formatted per page.

I'll keep looking for a solution I guess.

drupalace's picture

You could, of course, apply some per-page CSS formatting to a given block, if you wanted to, but I don't think that's what you're looking for. (Nice for changing a block's text size on a given page; not useful for swapping two blocks' positions on that page.)

As for controlling a block's region on a per-page basis, the only hack I know of is a crude one indeed: create multiple instances of the block (where possible), and have Version 1 appear in the right sidebar on the front page, Version 2 appear in the left sidebar on your contact page, etc. But that's certainly inelegant, and by forcing you to duplicate content for presentation purposes, is a punch in the gut to the praiseworthy CMS ideal of "separate content from presentation". : (

Unknown Drupaloid's picture

I followed all the instructions, but this one block I created will NOt show on the front page. I created another block that is showing just fine. Any ideas? Thanks!

Add new comment