5

I am using a views in my drupal web site. I have set 'style' to 'Unformatted' and 'Row style' to 'Fields'

Also I have Rewrote the output of the field with my HTML tags.

But I have a problem in the result. Every row is located inside a [div] tag for example the first row is located in

<div class="views-row views-row-1 views-row-odd views-row-first"></div>

How can I setup the view in order to remove this extra [div] tag ?!?!?

I don't need this wrapper.

6

If you don't want to touch the theme you could use Semantic Views module to strip all the extra div's.

  • Does the Drupal 7 version work well? – mpdonadio Apr 29 '12 at 18:06
  • 1
    @MPD it does on my site :) – Nathan Bomshteyn Apr 29 '12 at 21:03
  • @nathan6137, thanks. I have been hesitant to use it on a client site b/c there hasn't been activity of the project in a while. – mpdonadio Apr 30 '12 at 13:17
  • Semantic Views is not necessary if you are using Views 3.x - the functionality of SV is wrapped into Views core. drupal.org/node/740686 – sheena_d Apr 30 '12 at 13:42
  • @sheena_d, did all of the SV functioality get folded in? I thought it was just fields and that you couldn't pick elements for things like how rows in an unformatted list get generated. – mpdonadio Apr 30 '12 at 16:22
7

The easiest thing to do is copy the template files from "sites/all/modules/views/theme/" into you theme (I normally make a "views/" subdirectory).

If you want to make this change for all themes, edit "views-view-unformatted.tpl.php".

If you want to just change that view, edit the view then click on the Theme: Information link. It will show the template suggestions for the view. Copy If you want to make this change for all themes, copy "views-view-unformatted.tpl.php" to the proper name, and edit that file.

In both cases, make sure you clear the Drupal caches to make sure the system finds the new files.

4

This solution combines and builds on David Paul's and MDP's solutions and removes the <div class="views-row ..."> in a consistent way for all views that are properly configured without additional modules.

Drupal 7 & 8

Step 1: Disable all class configurations in the Style options of the view's Format section.

You must do this for any and all views that you want to remove the wrapper from:

Views Format Style Settings

Drupal 7

Step 2: Copy views-view-unformatted.tpl.php from the Views module into your theme's templates folder and modify the logic to ignore the div when classes are empty.

Change the following lines from:

<div<?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"';  } ?>>
  <?php print $row; ?>
</div>

to:

<?php if ($classes_array[$id]) : ?><div class="<?php print $classes_array[$id]; ?>"><?php endif; ?>
  <?php print $row; ?>
<?php if ($classes_array[$id]) : ?></div><?php endif; ?>

Drupal 8

Step 2: Copy views-view-unformatted.html.twig from the Views module into your theme's templates/views/ folder and modify the logic to ignore the div when {{row.attributes}} are empty.

Change the following lines from:

<div{{ row.attributes.addClass(row_classes) }}>
  {{ row.content }}
</div>

to:

{% if default_row_class or row.attributes is not empty %}
<div{{ row.attributes.addClass(row_classes) }}>
  {{ row.content }}
</div>
{% else %}
  {{ row.content }}
{% endif %}

Honestly, I'm not sure why the Views module doesn't do this itself... its a total WTF and could be a nice improvement for Themer's eXperience.

  • 1
    THIS is the correct answer – ajmedway Jan 4 '18 at 10:10
  • I've added instructions now for Drupal 8 to this answer. – JamesWilson Mar 31 '18 at 3:21
  • 1
    Should be the accepted answer in my opinion. – Sébastien Gicquel Apr 29 at 10:45
1

You want to look into the Theming: Information section and override one of the styled templates for your view. That's where the stuff happens. Be sure to use the Rescan button when you create an appropriately named tpl file, so that Drupal picks it up.

1

To remove this in Drupal 7 you can click on the Fields settings and turn off "Provide default wrapper elements"

enter image description here

0

If you're on Drupal 7 then you don't need to play with template files to remove the wrapper divs. Those wrappers come as part of the output, which suggests they can be controlled in the view, which they can.

Under FORMAT > Show: fields | settings - click settings, then uncheck the wrapper option. That's it.

  • 1
    that is not entirely true, even if you uncheck wrapper options, views would not let you remove all divs – loparr Mar 18 '13 at 11:10
0

I have achieved this by overriding views-view.tpl.php file. Copy this file from views module into your theme directory and remove the beginning wrapper. enter image description here

Also remove the div wrapping the $rows.

enter image description here

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.