3

I want to remove all the default Drupal markup around content types fields.

In Drupal 7, Fences does it like a charm, but its Drupal 8 version is not stable yet. Another choice would be Display Suite Extra, in Drupal 7, and we can do it with Control markup with field templates, but in the Drupal 8 version there isn't any admin/structure/ds/extras and Check the option Enable Field templates exists.

How can I get rid of the default markup field wrappers?

2 Answers 2

4

Depending on your project and goals there are a few solutions. Drupal 8 core itself generates very little markup, the field markup is now coming from a theme, and the markup from those base themes is much lighter-weight than D7's core. To get started you may want to review the new theme guide, and MortonDK's session from DrupalCon New Orleans.

Given the control you seem to be seeking, you should probably create a theme that's based on Stable (which is the default if you don't set a base theme). Then enable theme debugging, and as you find templates you don't like the output of, copy them from core/themes/stable/templates/... into your theme's templates folder. If you explore either stable or classy you'll see a variety of field templates in the field directory, and you can target them on a case-by-case basis in your theme as needed (theme debug will provide you the name suggestions you need to create the properly targeted file).

Some people are copying the entire stable theme so they have all the templates on hand from the start. If you did that you may also want to set the base theme to false so stable is disabled entirely.

You can also use the hook_theme_suggestions_field_alter() and hook_preprocess_field() in your theme's .theme file to make changes before reaching the twig files. If you use the Drupal console to generate your theme, the boilerplate code will come with a large collection of the preprocess functions already defined.

1

One possible and working solution can be is defining your own custom field templates. This will help!

3
  • yes, it worked,but it needs i override multiple fields, :(
    – Yuseferi
    Commented Jun 9, 2016 at 13:09
  • That's true. That's why am claiming it's just a possible solution, probably not the best one. If you want really 0 markup create you own theme without inheriting anything from a base class (classy for instance).
    – ssibal
    Commented Jun 9, 2016 at 13:13
  • the issue of this solution is with non-text fields
    – Yuseferi
    Commented Jun 9, 2016 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.