views:

42

answers:

3

I have two views in a Drupal page with the following structure:

<div>
    <div>Some content</div>
    <div> View 1 </div>
    <div> View 2 </div>
</div>

Now I want a wrapper div covering the two views:

<div>
    <div>Some content</div>
    <div class="wrapper">
        <div> View 1 </div>
        <div> View 2 </div>
    </div>
</div>

What is the best and easiest way to do this?

A: 

You'll want to create a custom .tpl file for this. It would be something like, but not exactly:

views-view-viewname.tpl.php

To find the file name, edit the views then look under Basic Settings > Theme.

Ian Silber
Thanks. So I should open the div in one view.tpl and close it in the other?
Niyaz
@Niyaz: Hmm - that would work, but it sounds fishy, as it limits flexibility (you'd always need to output both views in the right order, otherwise you'd have to adjust the templates). How do you inject the views to the page? (Depending on this, there might be a 'cleaner' solution)
Henrik Opel
I add them to the page as blocks
Niyaz
+1  A: 

A cleaner way would be to use the views_embed_view function to get the output from the two views, which you then wrap in a div.

Where to put this code and how to do it, would depend on how you are doing things now. You could create a block for it and gain the flexibility of blocks.

googletorp
A: 

You can also use Views attachments (Google around to figure out how to make them). So make View 1 a normal view and attach View 2 to appear after View 1. You will get a wrapper div around both the views.

Sid NoParrots
Guys this actually works! Please try it out!!
Sid NoParrots