How to set a page level variable that views has access to I'm trying to build a custom responsive theme using Zurb Foundation. I'm also using Views to render a grid of nodes, let's call them Events, that are each wrapped in Foundation classes to lay them out in a responsive grid.

The Problem:

The Foundation classes I need to use need to change based on the visible regions on the page.

For example, if the sidebar_first region is showing, each item in the events list needs to have the classes: columns large-4 medium-6 small-6.

If the sidebar is not rendered, each item needs the classes: columns large-3 medium-4 small-6.

I cannot find a way to evaluate which regions will be rendered at the time the View is being built. I'm currently using template_preprocess_views_view_unformatted() to add the Foundation classes to the Views template, however this hook is being fired well before template_preprocess_page() for example, where I might be able to evaluate the visible regions and set a variable with information about the sidebar.

See the below pseudo code for the ideal structure when the sidebar is rendered:

&lt;div class="row"&gt;
  &lt;div class="region-content columns large-9"&gt;
    &lt;div class="row"&gt;
      &lt;div class="views-row columns large-4"&gt;...&lt;/div&gt;
      &lt;div class="views-row columns large-4"&gt;...&lt;/div&gt;
      &lt;div class="views-row columns large-4"&gt;...&lt;/div&gt;
      ...
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="region-sidebar-first columns large-3"&gt;...&lt;/div&gt;
&lt;/div&gt;


See the below pseudo code for the ideal structure when the sidebar is not rendered:

&lt;div class="row"&gt;
  &lt;div class="region-content columns large-12"&gt;
    &lt;div class="row"&gt;
      &lt;div class="views-row columns large-3"&gt;...&lt;/div&gt;
      &lt;div class="views-row columns large-3"&gt;...&lt;/div&gt;
      &lt;div class="views-row columns large-3"&gt;...&lt;/div&gt;
      &lt;div class="views-row columns large-3"&gt;...&lt;/div&gt;
      ...
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


Ideally, without the sidebar rendered the events will be 4 across spanning all 12 columns. With the sidebar rendered they will be 3 across spanning only 9 columns, as the above classes in the pseudo code imply.
I must be addicted to Drupal because it is Christmas and I'm working on this, but here goes.

Delete the page display of your view so that only the master display is left. Then create a custom module with this code in it. (I created a module 'custom', my view is called 'zurb', and my path is 'zurb').

In custom module:

function custom_menu(){
  $items['zurb'] = array(
    'page callback' =&gt; 'custom_zurb_callback',
    'access callback' =&gt; true,
  );
  return $items;
}

function custom_zurb_callback(){
  $view = array(
    '#theme' =&gt; 'render_view',
    '#view' =&gt; 'zurb',
  );
  return $view;
}

function custom_theme(){
  return array(
    'render_view' =&gt; array(
      'variables' =&gt; array(
        'view' =&gt; NULL,
        'display' =&gt; 'default',
        'args' =&gt; array(),
        'regions' =&gt; array(),
      ),
    ),
  );
}

function theme_render_view($variables){
  $view = views_get_view($variables['view']);
  $view-&gt;set_display($variables['display']);
  $view-&gt;set_arguments($variables['args']);
  $view-&gt;pre_execute();
  $view-&gt;custom_regions = $variables['regions'];
  $view-&gt;execute();
  return $view-&gt;render();
}

function custom_preprocess_page(&amp;$vars){
    if (current_path() == 'zurb' &amp;&amp; count($vars['page']['sidebar_first'])) {
      $regions = array();
      $regions[] = 'sidebar-first';
      $vars['page']['content']['system_main']['#regions'] = $regions;
    }
}


Now in your views template file or views preprocess function you can access $view-&gt;custom_regions.

Perhaps there is a better way to pass the $regions to the view than adding it as a member on the $view object, but I don't see it being a problem. If it is a concern you can always just use drupal_static

This code is also re-usable as it uses a theme function.