Extra DIV appearing in all my views fields - how can I remove it?

Events happening in the community are now at Drupal community events on www.drupal.org.
srebelo's picture

Hi all,

I'm currently trying out the Sky theme based in the 360 grid system (Drupal 7). So when trying to add a custom class to my view fields, I end up with an extra DIV in all of them, breaking the layout. I'm having something like:

<div class="views-row views-row-2 views-row-even views-row-last">
    <div>       
         <div class="grid-2">
             <p>Some text here</p>
        </div>
   </div>
   <div>       
         <div class="grid-6">
             <p>Some other text here</p>
         </div>
   </div>
</div>

I'm setting the rows to be unformatted. I tried all the possible combination in the "Style Settings" but still that extra DIV wrapping the field.

Is there a way to remove it without rewriting the results? I thought using patterns and rewriting the output manually but that is exactly what I'm trying to avoid.

Big thanks in advance!

Comments

Views theme information

c4rl's picture

It's likely that you have to override the template being used to format each views field.

In the views edit form, expand the Advanced fieldset, and click Theme: Information. This displays a list of the templates currently being used to format/wrap each component of the view (each field, row, and entire view). Creating an instance of one of these files in your theme's directory can override per view/display/field as shown in the list -- there is a great degree of specificity.

You'll copy the markup in the default template being used and save as a new file in your theme directory with the corresponding filename denoting the specificity (whether it be for all displays, one display, one field, etc).

Remember to clear the Drupal cache after creating this file to let the theme registry detect it. Your new file will allow you to add/remove whatever wrapping markup you need.

Since preprocess functions are available by default for every Drupal template, you have the option to add your own variables in a preprocessor in template.php to create content-sensitive classes. For example, you could use the "Has new content" field to set an "unread" class on a table row to set a different background color and text treatment (like an inbox). See http://drupal.org/node/223430 for more information.

©c4rlMaybe you don't answer

mr.oobov's picture

©c4rl
Maybe you don't answer his question.

If in a views template, for example you wrote something like :

<ul>
     <li><?php print $fields['field_exemple']->content; ?></li>
</ul>

What you will get is :

<ul>
      <li><div>My exemple content</div></li>
</ul>

And if you check in Views information the source code of views-view-field--whateve--block--field-exemple.tpl.php
You will find :

<?php
print $output;
?>

The extra div is actually inside the $output, so you can't really custom the field to remove the extra div using the field template.

I'm actually looking for the way to remove that extra div from $output, in vain.

I've just found the answer by

mr.oobov's picture

I've just found the answer by myself, so i explain here.

By default, in views, in your field option you got Style settings > Customize field HTML unchecked.

It is a lie :)
My extra div comes from here.

What i need to do is to check Customize field HTML and to mention i want nothing at all.

Thanks!

geocalleo's picture

Hey this worked perfectly. Thanks for finding the answer.

Perfect it works for me

smndey's picture

Thanks

You can change the row

gionn's picture

You can change the row formatting by overriding the views-view-unformatted.tpl.php in your theme.

Removing all wrappers

kq_sb's picture

Or, to be more specific, you can create an override template per view as follows:

views-view-unformatted--[view-id]--[view-type].tpl.php

eg views-view-unformatted--create-product--block.tpl.php

Doesn't work for me. As i am

daajack's picture

Doesn't work for me.
As i am a clean html lover, and want simple css, i wanted to use templates for display modes (default, teaser, ...), and not using field mode.

So i overrided modules/field/theme/field.tpl.php copied in my theme with content :

foreach ($items as $delta => $item) print render($item);

I think there may be problems with other mode, but for now it seems ok.

An option

BernardGatt's picture

An option which I am not a big fan of is using a module called Semantic Views (http://drupal.org/project/semanticviews), basically change the type of the view from unformatted to semantic views and in settings remove div.

It works but I would love to see this available within the views module..

Theme development

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: