Fragmented Thought

Alter Drupal Views display options at the theme level

By

Published:

Lance Gliser

Heads up! This content is more than six months old. Take some time to verify everything still works as expected.

My client today need the mobile version of the retailer locator to shrink down and fit the new mobile theme. Going from about 700px wide to 300ish, with a height change as well. The cleanest route I found for doing this is to have the theme itself alter the view just before rendering. Here's the code, pretty simple once you get past all the dominating recursion.

It's important to understand exactly what all that recursion is... Nothing. It's all left overs you don't actually have to interact with when you need to update just the display options. What you need, is not in $view->display or any such silly recusiveness. All of the display options you might need to change should be easy to find at the top level: $view->style_plugin.

In your template.php file:

function phptemplate_views_pre_render(&$view) { if( $view->name == 'local_retailers') { $view->style_plugin->options['macro'] = '[gmap behavior=+autozoom|width=300px |height=400px ]'; } }