Skip to content Skip to navigation

Managing layouts using Context

If your site has a lot of blocks, you should definitely consider using the Context module to help manage your layouts. Context lets you define rules for when blocks show up where (among other things).

Context lets you define contexts based on path. You can also use path* to define rules for entire sections of your site. For example, you should always consider setting up a context for your homepage, and a sitewide context (for blocks that appear everywhere). Other contexts you might consider creating are for specific sections of your site where you want a block to always show up in the sidebar for all pages in that section.

Setting up a path-based layout using Context

First, make sure the Context module is installed an enabled (as well as any dependent modules).

1. Set up a Context

From your admin menu, go to Structure > Context.

Admin menu bar structure - context

 

Create a new context by clicking "Add"

Enter a name for your context. This must be computer readable so you’ll use lowercase letters, dashes or underscores, and no spaces.

Enter a tag. This optional tag is used to group similar contexts on the Context UI page. Helpful if you have a lot of contexts.

Enter a description. This optional field allows you to describe a context in human readable terms.   

To add conditions for your context, click on the <Add a condition> drop down, and select Path.  

This will bring up a text edit field. Enter paths, one per line, that describe where you want the context to be effective.  
For example:
events
events/*

2. Add Reactions (Blocks) to Your Context

To add reactions, click on the <Add a reaction> dropdown menu.

Select Blocks.

This will bring up a long form listing all the regions available on your site.  In the column to the right of this list, about halfway down the page, is a scrollable list of blocks. Use your mouse to scroll through this list and select the blocks you wish to place in a single region.

Once you've selected the block you want from the list of blocks, in the center column, click on the + Add for the region in which you want to place the blocks, and the blocks should appear in the list for that region.

Drag the blocks into correct order with the +. (Note: experience has shown that even if the blocks initially appear in the correct order, upon saving, they may not stay. To pre-empt this, simply move them around and back into the correct order before saving.)

Once you’ve finished putting blocks into regions, click on Save.

Verify your work by navigating to a page described by the conditions in the context.