Hello

I am looking for a way to wrap two different fields in one single div. Actually I have 3 fields such as this :

  • <div class="views-field-title">
  • <div class="views-field-body">
  • <div class="views-field-field-image-slide-fid">

I would it to look like that :

  • <div id = "paging">
    • <div class="views-field-title">
    • <div class="views-field-body">
  • </div>
  • <div class="views-field-field-image-slide-fid">

Any ideas ? I tried to overide several template files form the theme:informations. But I cannot acces each field individually. Even I have $content (an array with all the fields) otherwise, there is the "field output" template files that deals each field separately by spitting it out throught the variable $output...

so I am a bit in a trouble here. If anyone has already done this before, it would help me a lot

Michael

Comments

mikou’s picture

I get into the same problem again :(

No idea ?

MBroberg’s picture

You can rewrite the output of one of your first 2 fields to include a token for field1 and field2. Then you can wrap them in a div.
Add html to your rewrite like this...

<div class="your-class-name">
<br>[field1]</br>
<br>[field2]</br>
</div> 

Your actual token list (replacement patterns) will appear in the field settings once you click on "rewrite the output of this field".
Make sure that whichever field you are rewriting appears in the field list below all of the fields you want to use.

Then exclude from display all of the other fields.
In the example above, my list would say
field1 (excluded)
field2 (rewritten)

You can also exclude field 2 and use it as a "group by" in an HTML list view style.

ChristianP’s picture

Thank you for that! Now I can finally make a background around some Views-div without gaps between them :D.

mikou’s picture

@Broberg

I was ready to make a new up today as I got stucked once again into the same problem. And obviously I wasn't the only one ;)
The solution was just very easy. That's the thing with Drupal. Every thing is there and very simple to use. But the problem here is about common sens ! I should had thought about it.

I really appreciate your help. Thank you again.

medieval111’s picture

Stupid I've never thought about that ;)
Thanks!

zetagraph’s picture

Thanks a lot for the tip

rootdownmedia’s picture

This is a great quickie way to do it. Just out of curiosity, are there any other easy ways to do this? Seems a bit hacky.

kiliweb’s picture

Thanks ! It works well but i agree with rootdownmedia, it seems a bit hacky.
Is there any other clean way to do it ? (without using a template file)

Anonymous’s picture

Semantic Views module is what you are looking for. You can customize html output for each field from within the views interface.

xbrianx’s picture

Just what i was looking for. Thanks

axiom3279’s picture

I have a field themed via custom tpl file -- views-view-....tpl.php. The issue is that I need to take this field and another and wrap them with a div. The tpl automatically inserts and

at the end to close any open divs (was hoping two field tpl files would have taken care of this, didn't work) :( . The rewrite option doesn't work when you override the tpl files.

axiom3279’s picture

Views 3: Uncheck the Provide default field wrapper elements under Format >> show >> Settings and the two tpl files will do the job.

yan’s picture

I wanted to achive this in Views 3 without to much code (tpl files) and maintaining the default wrapper elements for all fields.

I achieved it using two fields of the type "Global: Custom text" - one before and one after the fields I want to be inside one div. In the first I of them I put just <div class="xyz"> and in the second one </div>. Additionally, I had to set all the design settings for those fields to "none", disable the default wrapper elements and to not include any label.

It seems to work just fine.

pwiniacki’s picture

@yan, same here. I did manage to use one Global: Custom text with rewrite <div class="yourclass">[somefield]</div> - then [yourfield] is surrounded by div class.

Drupal beginer

rolfo85’s picture

hi,

You all should take a look to this module. Views fieldsets. It basically does whatever you want.

therio6’s picture

Thank you very much, very useful module!