Field strip outer div - formatter settings

This project is not covered by Drupal’s security advisory policy.

This module provides a simple way for themers to remove outer divs from fields directly from Manage display formatter settings.
You only have to override field.html.twig and you can have surrounding field divs for one field in one display and remove them in another display. No other field template override is required.

Installation

Install this module normally, just like you would install a contributed Drupal module. Visit https://www.drupal.org/node/1897420 for further information.

If you don't have one, create a custom theme (https://www.drupal.org/docs/theming-drupal).

Copy field.html.twig from drupal core (web/core/modules/system/templates/field.html.twig) or from the parent theme or your theme.

Use the code following code snippet to have both stripped or normal DOM version :

{% if stripouter_valueonly %}:

  {% for item in items %}
    {{ item.content }}
  {% endfor %}

{% else %}

  <!-- content from field.html.twig -->

{% endif %}

Clear your cache.

Go to your content type "Manage display" tab and edit your field display setting to control DOM output for one view mode or another.

Supporting organizations: 

Project information

Releases