Creating A Site With Drupal Context and Features

Submitted by Brandon Cone on 07/16/2012 - 01:15:pm

As a Software/Systems Engineer turned web developer I am still discovering some of the nuances and power of the Drupal community and framework.  While developing a new site for Meeting the Challenge, Inc. and the Rocky Mountain ADA Center, some of these tools were on full display.  The site designed required multiple page layouts with varying page content.  Some content was to be displayed site-wide, some on specific pages, and some on specific page types.  One of the challenges was finding a flexible solution which did not need additional configuration as content was added to the site.

Context

One of the primary issues with site building is fulfilling the design for different page layouts while staying within the budget - depending on the site design, there may be one layout or many.  So how to get the right information to display in the right place on the right page(s)?  Enter Context.  Context, the Drupal contributed module, provides this ability using conditions and reactions.  The power of context is that it provides multiple conditions as well as reactions.  You can configure an action based conditions such as: path, Taxonomy term, node type, and menu.  You can use negative logic as well as AND or OR logic for a set of conditions. 

The use of context in this project is was to create page layouts based on a combination of path and node type.  For each context we created, we then add the blocks and views to the appropriate region in order to fulfill the design.  You can see our implementation and how we accomplished this by browsing the site at adainformation.org.

But why not just use Blocks?

Blocks administration allows you to configure a block to be active on a certain page based on the URL and user's role as well as set the weight of that block within the region.  However, if ever you add a new page, you must go and update the block configuration to also display on that page.  This creates additional work in site maintenance and limits who can manage content.  Additionally, block administration only allows you to configure block display based on user role and path. 

Features

Since no one develops a site on a production system, the next challenge in deploying a new site, or updating an existing site, is moving the site configuraiton information which you have done (all your contexts) from one platform to another.  Option A is to nuke the production database with the udpated one from your development system.  However, anyone will tell you that this is not a recommended option and should never be done.  The best way to move site configurations between platforms is to use Features.  This allows you to export configurations you have made, including contexts you created and all their dependent informaiton - views, blocks, etc - into into PHP code.  This means that updates which requrie configuraiton changes only need to be done once.  This reduces the time required to deploy updates as well as the potential for errors or missed steps during the deploy process.  Because your site configuration is now built from source code

Conclusion: Context and Features facilitate increasingly robust and complex sites which, when configured properly,  do not require ongoing developer support for content management and as such they should be strongly considered for any new website work.