Working with Blocks

As we saw brie y in Chapter 2, blocks contain information or related data that is visible in various places around the site—depending on where you choose to show them. Blocks are often generated by modules, but it is also possible to create them manually. Since many modules generate blocks automatically, it is always wise to pay the blocks section a visit whenever a new module has been enabled, because it is likely there are some new settings to play with.

Basic Functionality

When we talk about working with blocks, what we are really saying is "How do we want to present the functionality of the site to the user?" Naturally, everyone should strive to make a striking and unique site, and layout configuration is a big part of that—especially since it governs how functionality is organized on the site's interface.

Keep in mind at all times that the overriding factors that govern the way to set things up when it comes to presenting the site are all about usability. Make sure that the site is intuitive, easy to follow, and never sacrifice clarity and ease of use for artistic reasons.

Luckily, Drupal is already fairly sensibly laid out by default, but that doesn't mean that there is not plenty to do. You have an exceptional amount of control over where and how everything is displayed, and correspondingly, quite a lot to work on.

One of the best ways to find out how you want things done is by looking on the Net and seeing how other people have made sites that work nicely. If there is something you like, see if it can be replicated.

Another way to learn about how you are ultimately going to set things out is to actually play around and see what works. This section will concentrate on this method and leave the rst method for you to research.

Adding Blocks

Under Site building, click Blocks to bring up the list of blocks that are available for the site at present. Remember that this list will change as modules are added and removed—you will probably have to revisit it more than once. The blocks page provides a list of the available blocks and several options for each one. Drupal gives you the ability to place any of these blocks pretty much anywhere on the page, but your choices shouldn't be quite so random.

It is generally a good idea to group related information into the same places on the site, so that users can get a feel for where they might look for a specific type of content. For our current purposes, the following settings are made:

Block Region Left sidebar

+ User login Left sidebar •f* DHTML: Navigation Left stdebar [»J

Right •¡¡ilebiir

Operations configure configure

+ Most recent poll

Right sid-abar -


+ Recent blag posts Sight sidebar JT]


+ Recent cojinnie lit? Right sidebar Jy|



No ¡ft iiiiff rsfion


■1" Search Form

Header *1



-f1 Who's online

Footer ¡t|


tf* Who's new

Footer f*~|


+ Powered by Qrupaf

Footer j -1


Notice that community related information, like Who's new and Who's online, is con fined to the footer area of the page. While this information might be of interest, it must be relegated to the bottom of the page to avoid detracting from the main content of the site.

Basic Functionality

All content-related blocks are grouped into the right-hand sidebar. This means that if people want to quickly take a look at what new content has been added to the site, they can nd it by looking here. Additionally, information is structured such that polls appear above all other information (because we generally want to encourage people to take the time to answer a poll), but we have left the Search form at the top of the page, because this should be one of the most useful tools once the amount of content on the site has become substantial.

Of course, some blocks remain disabled as the site does not need them for now. It is always easy to add or remove blocks at a later date. Provided you make sure there is a nice logical layout for the various blocks, you can chop and change what is and is not displayed as and when required. Try not to chop and change too often once the site is live as this impairs its usability and may lead to confusion.

Taking a look at your homepage once these changes have been saved (by clicking Save blocks), notice that the various blocks have now been inserted into the web pages. It's easy enough to move things around until you are totally happy with the way the page looks, but there is little point in spending hours and hours getting everything just perfect if you are going to change the theme at a later stage. Rather, make sure you understand how blocks works and come back to it after settling on a theme.

You may also have noticed that there is an Add block tab at the top of the Blocks page. Clicking this brings up a page that can be used to insert your own blocks into the site, as shown in the following screenshot:

b 113 c k descrl ption:

[unkDcozgr - Bookmark s-ite a tin.' 4*[eriptftn '!■ V4<if i»l.)tk. Lfi*d s* Hod tt«iM|ii till?:

Th* bHi of if-* block, ii ihotn to th* Block boily;

lintdo0ier,«jtn;aK0u»ic.pi-iii?nafne-1 t-escaptifdotumerit.titlej +■ 'acfcua-rfif + 'fturl-' + eieaiflBflcMtionhrafVUriltttooKwV neignt-soo. ^idcn-tsi, rotation-no, scrollbars-yes., menubaf-irGi, toolbar-yes, directories-no, fesirjole-yes'));" Xirns irc-",|-,tTp://www.liflkdD0Ser.i(jnn/d00Zer_iC0ri png ' .irt-'E'tJOrerm^rlf Me" titie^"DnozemiflJrk tins Psge'' border*"!}" /a [jaosermark this site1c/a>

In this case, we have added a link provided by a free online favorites site called LinkDoozer (http: //www. linkdoozer. com) that allows users to add sites directly to their online favorites list at the click of a button. Doing something like this is a great way to gain exposure for your site because at least in the LinkDoozer community, users can review and recommend a site to other community members.

In general, be wary of adding 3rd party JavaScript to your pages. Make sure you trust the authors of the script before adding something like this.

Notice that the Block title section was left blank because this block should not take up any more valuable screen real estate than is absolutely necessary, and the link that is displayed is fairly self explanatory anyway so any name added here would simply waste space and be redundant.

It is likely that you want everyone and anyone to add your site to their favorites, so setting this block to display prominently on each page makes sense:

Vfr PnozermarL ttlii Site'

Market Force for Good


Clicking on the new link confirms that it is working, as evidenced by the reply from LinkDoozer:

Doorariwrkec) lo your favorites ' 'tdai Pisses open up your LlntOo&Mr homepage (or refresh t if it Is already open) to vten your new iirfcs

Remerriber. you «n e«Hy drag jnd drop this bookfnarti Into any other category In ycxjr LinkDoozer homepage

Cis15? elite Popup

Basic Functionality

The situation becomes more complex when we start thinking about whether certain people should be allowed to access a block or not, or whether the block should be displayed on all pages or only on selected pages. In order to find out how to deal with these issues, we must look at block configuration in some detail.

Configuring Blocks

Drupal allows us to control when a block is displayed through the configure link at the right-hand side of each block in the list. This configuration page is split up into four main sections that deal with:

Block specific settings User specific visibility settings Role specific visibility settings Page specific visibility settings

Combining these provides a sophisticated method of controlling when a block is shown, and to whom. Of course, some modules don't require any specific settings of their own; in which case you are only required to make specific decisions about users and pages.

A good example for configuring a block can be shown by the Who's online page. This page allows us to decide how long users can be inactive before we no longer consider them online, as well as the maximum number of people to show at any one time. That's easy enough to deal with, and really depends on the needs of the site.

The other options give us something to think about though:

User sp^crfic viability settings CustPrii viiiliiirly settings;

O Users cannot control whether or not they see this biock-® show this biocfc by default, but let individual users hide it. O Hide this block by default but let individual users show it;

AHo* .ndI'.'iduUFifi ta wrtinrili« Iho visibility ofthi; tliit. In their nc^unt rflttlrigj.

Role specific visibility settings Slutw lilacK fur specific rules:

El anonymous user 0 authenticated user ii.h-ij block only for tha selc-rtcd rolef^. ]f vou seilet ro ro'et ihc blocV -.'-l- be ULSiiio to «II Uftrf,

Page specif* visibility sittings shai-f blhLk an specific pagei: O shov* on e^erv pige except the listed pages. 0 show on only the Nsted paaes-

O Show if the following pup code returns tfve (PHP-mode, experts only}.


Exits' on;* pjac per lint m Dfupal pi'.hi, The dWartor u a vildcjfrf, fj^rYipfe palhs krk frtaj for the blag and tin/* for e^iry pe=sonal blofl. <fror,i:> it (he- front siQi, IF (he

Oh<P-mode is choierp, antei PHP between ^¡t^p l^ate thai «Kecuiing inoorrcct iHP-(o(Jt tin b'Sii vow* &rjp*l jife.

Basic Functionality

The settings shown in the previous screenshot allow users to edit their own preference for whether they can see the Who's online block—leaving all roles unchecked allows the block to be displayed for all users. We will look at how to create different roles in Chapter 5 and this will require you to return to this page to re-specify the Role specific visibility settings if necessary.

With these settings in place, users editing their account information are presented with the following checkbox that allows them to enable the block or disable it:

ti-ock cofiiigLirstJOn Who's online

Looking at the screenshot before last again, notice that the Show on only the listed pages option has been selected and the text <front> has been entered in the Pages text area. This means that whenever someone visits the site, they are shown who is online but as soon as they begin using the site and move away from the home page, that information is no longer visible.

People with PHP experience have the ability to add some code to determine whether or not the block is displayed. This could be in the form:

if (some_condition_is_true){

return TRUE; }else{ return FALSE;

As always, it is recommended that you play around and attempt to show a block on a certain page but not others. For example, can you prevent a block being shown when someone is using the forums? The answer is of course to select Show on every page except the listed pages option, and then enter forum* into the text area. Make sure this is correct by trying it out on your own machine.

Completing the site's block configuration is simply a case of going through each enabled block, and making the appropriate decisions about when, where, and to whom it will be displayed. At present though, this is not quite the full picture because we have not yet discussed users, roles and permissions, so be prepared to revisit this after Chapter 5.

Chapter 3
0 0

Post a comment