1

How to add strip tag in field template i am using ckeditor in my content type because of using it its automatically inserting p tags in Text.

Here is mine field template code

         {% for item in items %}
     <div{{ attributes.addClass(classes, 'field--item') }}>{{ item.content }}</div>
{% endfor %}

I was trying something like this for adding strip tags

{% for item in items %}
{% set conBody %}
 {{ item.content }}
 {% endset %}   

{{ conBody|striptags }}

 <div{{ attributes.addClass(classes, 'field--item') }}>{{ conBody  }}</div>
{% endfor %}

Only indexed value(conBody[0]) field tags are stripped(p tags removed) but remaining indexed value fields are remaining same not affected.

How could i use above code in loop.

2
  • I'm confused, why would you provide CKEditor on a field that you want to strip all tags from?
    – Kevin
    Commented Apr 25, 2017 at 13:13
  • Its a clients requirement he wants ck editor fields to style its content by using inline css
    – user59414
    Commented Apr 25, 2017 at 13:26

1 Answer 1

2

I ran across this today and figured I would circle back and provide an answer that worked for me.

{% for item in items %}
    {% set conBody %}
        {{ item.content }}
    {% endset %}
<div class="myClass">{{ conBody|striptags }}</div>
{% endfor %}

Your Answer

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