0

I'm very much beginner to the drupal and learning to themeing, and I'm confused how to make regions within the regions?

+----------------------------------------------------------+
| +--------------+                +---------------------+  |
| |              |                |                     |  |
| |    header1   |                |   header2           |  |
| |              |                |                     |  |
| +--------------+                +---------------------+  |
|                       header                             |
+----------------------------------------------------------+

page--front.tpl.php

<header>
   <div id="header1">
    .....
   <?php print render($page['header1']); ?>
   </div>

   <div id="header2">
    .....
   <?php print render($page['header2']); ?>
   </div>

<?php print render($page['header']); ?>
</header>

And I did the change in .info file like:

regions[header1]        = Logo Area
regions[header2]        = Search bar and Navigation

But it's not displaying as the picture describes better it:

enter image description here


Update:

The rendered html is like this:

<header role="banner" id="header" class="header">
    <div id="header1">

    </div>
    <div id="header2">


    </div>

<div class="region region-header">

</div>
</header>

But What I wanted to be like this:

<header role="banner" id="header" class="header">


<div class="region region-header">
    <div id="header1">

    </div>
    <div id="header2">


    </div>
</div>
</header>
6
  • Which theme you are using ? – Rupesh May 5 '14 at 11:27
  • 1
    What you did seems valid, and should only need a proper CSS to work. Strictly speaking it is not "region in region" but should display all right. Just don't expect Drupal to show it as nested regions, as this concept is unknown to Drupal. – Mołot May 5 '14 at 11:28
  • @Rupesh Zen theme – Navin Rauniyar May 5 '14 at 11:29
  • 1
    Did you clear the theme cache after you made the changes ? – Fero May 5 '14 at 11:29
  • Yes clear the cache, but no avail.... – Navin Rauniyar May 5 '14 at 11:30
4

You cannot make region within region. You can place block in a region. Fix the width of block and float that. You have to use only css to achieve that.

Print wrapper like this

<header>
<?php if($page['header1'] || $page['header2']) :?>
    <div class="region region-header">
    <?php if($page['header1'] ) :?>
        <div id="header1">    
        <?php print render($page['header1']); ?>
        </div>
    <?php endif;?>
    <?php if($page['header2'] ) :?>
        <div id="header2">    
        <?php print render($page['header2']); ?>
        </div>  
    <?php endif;?>
    </div>
<?php endif;?>
</header>
9
  • 1
    please answer in detail what should I do? – Navin Rauniyar May 5 '14 at 11:28
  • 2
    CSS questions are off topic here @Navin, we won't be able to help you with that – Clive May 5 '14 at 11:32
  • @Clive No, I'm not talking about css, I know css very well, but the problem with the rendered markup.... – Navin Rauniyar May 5 '14 at 11:33
  • Ok, but you still can't put a region inside a region... blocks go in regions, so usually one would put their content in blocks, add them to a region, and use CSS to produce the desired layout. Anything beyond that and you'll need a custom region template file (a quick search on this site should show you how to do that, but if not just update the question). Bit there is no native support for putting a region inside another region – Clive May 5 '14 at 11:36
  • 1
    Sorry, I don't know another way to phrase it - you cannot put a region inside another region. You'll need to adjust your strategy to use blocks instead. Or add another concept to your theme (like Omega does with 'zones'), but that would be a lot of work. If you're desperate to have that exact markup I don't understand why you don't just manually wrap the output of the two regions in the markup you want, directly in page.tpl.php – Clive May 5 '14 at 11:41
1

you cannot put region into region, but you can fake it

<header>
  <div class="region region-header">
   <div id="header1">
    .....
   <?php print render($page['header1']); ?>
   </div>

   <div id="header2">
    .....
   <?php print render($page['header2']); ?>
   </div>

   <?php print render($page['header']); ?>
 </div>
</header>

now you dont want that extra div with classes to appear in header region so you theme it and remove div. create region--header.tpl.php

and put this inside:

<?php if ($content): ?>
    <?php print $content; ?>
<?php endif; ?>
2
  • there is no region.header.tpl.php but pane.header.tpl.php should I create one... – Navin Rauniyar May 6 '14 at 4:55
  • yes. you need to create region--header.tpl.php but not region.header.tpl.php you can copy and rename modules/system/region.tpl.php but then you need to remove div wrapper from there – Mantas Karanauskas May 6 '14 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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