0

The output from the below code is printing HTML. How can I make the "p" tags disappear?

<p>answer 1</p>
{% block paragraph %}
  <div {{ attributes.addClass(classes) }}>
    {% block content %}
      <h1>{{ content.field_accordion_title.0}}</h1>
      {% for grid_item in paragraph.field_accordion %}
        <button class="accordion">{{ grid_item.entity.field_accordion_list_item_headin.value }}</button>
        <div class="panel">
        {{ grid_item.entity.field_accordion_list_item_text.value }}
        </div>
      {% endfor %}
    {% endblock %}
  </div>
{% endblock paragraph %}

Note: I don't want to trim the HTML tags but actually render them. Perhaps drupal_entity() will help to render the output of {{ grid_item.entity.field_accordion_list_item_text.value }}. How can this be done?

Note: I don't want to trim the HTML tags but actually render them. Perhaps drupal_entity() will help to render the output of {{ grid_item.entity.field_accordion_list_item_text.value }}. How can this be done?

3
  • 1
    Does this answer your question? How to safely render node body on a custom variable?
    – Hudri
    Nov 19 '20 at 16:21
  • Have you tried striptags, for example: {{content.field_media_image.0|render|striptags|trim}} Nov 20 '20 at 2:18
  • Sorry for not being clear, I don't want to trim the HTML tags but actually render them. Perhaps drupal_entity() will help to render the output of {{ grid_item.entity.field_accordion_list_item_text.value }}. How can this be done?
    – brainHax
    Nov 20 '20 at 4:11
0

Try {{ grid_item.entity.field_accordion_list_item_text.processed }} instead of {{ grid_item.entity.field_accordion_list_item_text.value }}

i.e. replace value with processed

-1

I assume the string <p>answer 1</p> is escaped and printed but you want to actually render the HTML tags.

In that case {{ grid_item.entity.field_accordion_list_item_text.value | raw }} should do the trick, assuming the variable is safe. If the value was entered by a user, take a look at this: How to safely render node body on a custom variable?.

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.