Using Context for Campus Maps

By peterm, 6 March, 2011

Tags

Some of the final touches are reviewing the work done for campus maps (http://maps-dev.ucsc.edu) and trying to get as much into code as we can. One way of doing this is by using the Context module. This will allow us to create conditions and reactions for different sections of the site. We can then export this information from the database to the filesystem where it can be managed in git or svn.

Here's a simple example of what I'm trying to do. Maps is driven by node items of type map_item and bike_item. We plot buildings and departments as nodes of map_item. Each node has fields in it that can be set for various categories of information; cafe, dining hall, coffee cart, etc. Other content in the site consists of traditional Drupal pages; Help, About, References.

What I'd like to do is hide some of our navigation blocks when we're on the Help pages. When we're on any of the views that show map_items, I want to show all our navigation blocks. Couldn't I have managed this with the blocks module? Yes. Here's why I didn't.

As we move data from dev->stage->prod, I don't want to spend a lot of time setting up the blocks logic. I'd like to set it once in the dev site and flow those configurations out to prod. Since I'm just starting to let other folks in on the workflow, I need to establish some good practices to make this effort more sustainable (management hat) over the long run. 

So, here's the basic configuration. For my map nodes, we need to include the front page path and the views that make up the Common Searches on the site - those are the conditions. The Reactions, are to show the blocks we want to see when the conditions are met. So, when we're on the front page view, I want all the navigation blocks showing.

For the 4-6 pages we have on the site, I want to only show the Common Searches block. So here, the condition is based on the node type Page. The reaction for a Page is to only show the Common Searches block.

Ok, that works. There's a lot more sophistication we could be taking advantage of, but these are pretty simple use cases.