1

In Views module, if I don't use any classes, even not the default, it still insists of wrapping the field contents into divs. I have had to use views-view-fields--VIEW-ID.tpl.php to theme the content, when it would had been very easy to tell Drupal not to warp with divs. Surely I am doing something wrong in the UI of Views, but I cannot identify what: in each field, the Style Settings has every checkbox unchecked, even the "Add default classes" checkbox.

2

On the contrary, you NEED to select the boxes for field, label and wrapper, and select None in the drop down menu. This will get rid of the <div>.

enter image description here

The Add default classes has nothing to do with the HTML elements - only with the css classes it adds to the tag.

Additionally you can deselect Provide default field wrappers under Format > Settings enter image description here

EDIT: So, testing confirms that there are NO divs for fields anymore if you uncheck Provide default field wrappers. See image. Why modify a tpl file if you can do this with the interface? The only divs you see in the image are the ones that separate rows in the Unformatted list output. "See, mom, no divs!"

enter image description here

|improve this answer|||||
  • I see other answers that advise you to modify with the tpl file. Why??? You can do this easily with the Views UI following the directions above. The only DIVs that will be added are the ones separating rows. NO field DIVs if you uncheck "Provide default field wrapper elements" as above. – argiepiano Nov 20 '15 at 17:33
0

Here is default views-view-fields--VIEW-ID.tpl.php template:

<?php foreach ($fields as $id => $field): ?>
  <?php if (!empty($field->separator)): ?>
    <?php print $field->separator; ?>
  <?php endif; ?>

  <?php print $field->wrapper_prefix; ?>
    <?php print $field->label_html; ?>
    <?php print $field->content; ?>
  <?php print $field->wrapper_suffix; ?>
<?php endforeach; ?>

You can remove all wrappers by doing this:

<?php foreach ($fields as $field): ?>
  <?php print $field->label_html; ?>
  <?php print $field->content; ?>
<?php endforeach; ?>

Or even like this:

<?php print $fields['FIELD_NAME']->content; ?>

Note that after those changes you won't have possibility to change wrappers through Views UI.

|improve this answer|||||
0

You're doing nothing wrong. Altering the view templates is the only way to get rid of the divs.

|improve this answer|||||
  • 1
    Actually, this is an answer to the question. The question is: How can the divs added by default by Views be removed? My answer is: By altering the view templates. – Patrick Scheffer Nov 20 '15 at 15:49

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.