Programmatically show field in different regions depending on content I'm creating an Omega sub theme &amp; three regions ("Sidebar 1", "Content" &amp; "Sidebar 2") inside of the "Content zone". "Sidebar 1" &amp; "Content" are both set to always show, "Sidebar 2" however is set to only show if there's content inside of it.

I also have a field which contains links related to the page, this is output programmatically into all three regions but CSS hides all but one. This is done so it can be shown in the "Sidebar 1" region which stacks above the "Content" region on small screens but on larger screens it'll be hidden in the "Sidebar 1" region &amp; shown in the "Sidebar 2" region instead, on the right hand side. If "Sidebar 2" doesn't exist it'll then be shown in "Content."

"Sidebar 1" pretty much only contains a menu, only on some pages though, which is again programmatically output. The reason being that I want to label / title of the menu to be set to the name of the currently active page and it was the best way I could see of doing it.

I've almost got it all working as I have a class set on the content zone div which states how many regions are inside of it (2 means no "Sidebar 2", 3 means it's there) &amp; the first sidebar now adds a class stating if it's empty or not.

I've attempted to add a class to the "Sidebar 2" region by using drupal_get_region_content("sidebar_1") to detect if the "Sidebar 1" region is empty of not and add a class to the "Sidebar 2" region based on this will CSS selectors will use. Problem is no mater what I try or what region I try to output drupal_get_region_content always returns NULL.

The basics of what I'm trying to do
I'll try and write here what I'm wanting in a more concise manor, above I've also included how I'm trying to do it.

I have some pages with three regions in the content zone, I want to output a field in all three regions so they can be shown &amp; hidden at different screen sizes with CSS.

The left sidebar might have a menu in which is added programatically. If it does not have this then the second sidebar doesn't need to the field I'm outputting programmatically will just be shown in the first sidebar &amp; main content area.

I realise this is very long, appreciate anyone who's read it and any help you can offer.
"I have some pages with three regions in the content zone, I want to
  output a field in all three regions so they can be shown &amp; hidden at
  different screen sizes with CSS..."


If this is the case, you could solve this entirely in CSS, by using media queries to show / hide areas -or your field -depending on the browser size. And you don't even need to have the same field in all the three regions.

However, if what you want is to show / hide columns inside your content depending on a field value, you might be looking for the Display Suite module, which allows you to easily create different layouts and view modes. For example, you could:


Create one view mode with 2 columns and another one with 3 columns. 
Add the fields you want to display in each one of those view modes.
If you want to switch the view mode, depending on whether a field has a value or not, you could use hook_entity_view_mode_alter() like this:

function YOUR_MODULE_entity_view_mode_alter(&amp;$view_mode, $context) {
  // If viewing a node in the two_columns view mode... 
  if ($context['entity_type'] == 'node' &amp;&amp; $view_mode == 'two_columns') {

    // If your field 'something' has a value, change the view mode to 'three_columns'.
    if (!empty($context['entity']-&gt;field_something)) {
      $view_mode = 'three_columns';
    }
  }
}



Or you could also use the Contextal View Mode module to change the view mode for a node based off of a context.