Working with Blocks

Blocks are the chunks of text or information that appear on the left and/or right sides of site pages. (Some site layouts can also sport blocks at the top and the bottom of pages.) 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

Arranging blocks

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

Immediately below List, you'll probably see several links. These are links for various graphic Themes your site may be able to use, allowing you to set different block configurations for each Theme. There's no need to worry about it now.

Below that are some built-in, brief instructions on administering blocks.

Below that is a list of blocks available for your site (though most of them likely don't yet show up on your site). The blocks appear on the list in groups according to where on pages they're currently set to appear, or under the group 'Disabled'.

Blocks are listed with the following columns of information:

Block

A description of the block. (Not all of the descriptions are necessarily easy to understand...)

Region

Where on the page the block will appear. You can set a block's region freely. (If you look carefully around the Blocks form, you'll see these region names appearing where the blocks will appear. Only the block form offers this visual guide to page regions.)

If region is set to <none>, the block will not appear at all – that's how you "turn off" a block.

If region is set to "left sidebar" or "right sidebar", the block will appear along the left or right side of the page, respectively.

You may also have options for "header", "footer", and "content". These place the block toward the top of the page, bottom of the page, and within the main content of the page, respectively. Not all blocks will fit well into those regions, though; some Themes may not allow blocks there at all. Feel free to experiment, but for now let's focus on the favored regions for blocks, the left and right sidebars.

Weight

If you have multiple blocks in a given region (as you often will), weight determines the top-to-bottom order of those blocks. You can freely assign each block a weight, from -10 to 10. "Lighter" weights (lower 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. "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

Your block form may have a check box with this name. Checking the box will turn off the block when your site comes under a heavy load – i.e., when it's being visited by many readers. Those crowds can slow down your site, resulting in some frustrated visitors; 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.)

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) Leave block visible to everyone: leave all roles unchecked.

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

c ) Leave 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/.

Under either option, you can specify multiple pages; just hit return after each one, entering one page per line.

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.

Creating blocks

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

The resulting form is simple, with only two 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 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.

Input the information and click 'Save block'. Your browser will go back to the Blocks administration form, and you'll find your new block somewhere on the list under Disabled.

Configuring your new block

You can now set your new block's region and weight, 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.

Average: 5 (1 vote)

Trackback URL for this post:

http://www.drupalace.com/trackback/98

Re: Working with Blocks

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.

Re: Working with Blocks

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". : (

Re: Working with Blocks

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.

Re: Working with Blocks

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!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><br><p>
  • You may quote other posts using [quote] tags.
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
Sorry for the "captcha" spam-detector challenge; the spammers have been out in force. : (
space_light: