0

I'm creating an Omega sub theme & three regions ("Sidebar 1", "Content" & "Sidebar 2") inside of the "Content zone". "Sidebar 1" & "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 & 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) & 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 & 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 & main content area.

I realise this is very long, appreciate anyone who's read it and any help you can offer.

5
  • I'm not sure I understand what you are trying to do. So, what do you mean by "field" here, do you mean a "block"?
    – typologist
    Jul 17, 2015 at 18:16
  • Sorry, I thought this would be a bit confusing to explain. By field I mean a field which is completed by the user when creating a node, not a block. It's a field actually added to the content type. It's being programmatically added so it can appear in all content zone regions and shown / hidden depending on screen size to get it to appear in the correct location.
    – Neil Nand
    Jul 17, 2015 at 18:19
  • So, basically, you have 3 columns inside your content area. And you want to show / hide the third one depending on whether a node field is empty or not?
    – typologist
    Jul 17, 2015 at 18:23
  • Close, I want to show & hide the third one based on if the first one has a menu in it or not. If it doesn't have a menu then I want the third one hidden, if it does have a menu I want it to show.
    – Neil Nand
    Jul 17, 2015 at 19:06
  • Perfect. Check my answer below and let me know.
    – typologist
    Jul 17, 2015 at 19:23

1 Answer 1

0

"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 & 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:

  1. Create one view mode with 2 columns and another one with 3 columns.
  2. Add the fields you want to display in each one of those view modes.
  3. 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(&$view_mode, $context) {
      // If viewing a node in the two_columns view mode... 
      if ($context['entity_type'] == 'node' && $view_mode == 'two_columns') {
    
        // If your field 'something' has a value, change the view mode to 'three_columns'.
        if (!empty($context['entity']->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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.