I have a paragraph template in my custom theme as paragraph--home-page-carousel.html and when I write like this

<span class="car-spec">{{ content.field_home_slide_snippet[0]|raw }}</span>

I get in HTML source code this

    <span class="car-spec">

what should I do to remove the div wrapper?


You shouldn't do {{ content.field_home_slide_snippet[0]|raw }}. You should do {{ content.field_home_slide_snippet }} and edit the twig template for field--field-home-slide-snippet.html.twig to have no HTML wrappers. Copy field.html.twig to your theme and edit as needed.

  • 2
    Thank you, Kevin but I tried this and still get the "div". – Mohamed Osama Gbril Dec 12 '17 at 4:55
  • 1
    Did you also edit the paragraph twig and remove the div? If you enable twig debugging it will tell you what templates are being used. – Kevin Dec 12 '17 at 12:39
  • 1
    Yes I removed from the both. I enabled devel and twig debug and tried these templates – Mohamed Osama Gbril Dec 12 '17 at 13:13

You could use the strip tags filter : {{ some_html|striptags('<span>') }}
Assuming the html is dynamically wrapped by the <div> tag, this will strip the <div> tag and leave the <span> tag.


{% set mycontent %}
    {{ content.field_home_slide_snippet }}
{% endset %}
{{ mycontent|striptags('<span>') }}



I think you can use

{{ content.field_home_slide_snippet.0["#context"].value }}

or enable devel module and then use

{{ kint(content.field_home_slide_snippet) }}

to see where is value that you need.

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.