1

I have a view that has two blocks. The blocks are essentially the same except for their filtering options. One uses contextual filters and the other uses BEF exposed filters.

Both output matching node body content in full.

Both make use of the same twig template: views-view-fields--VIEW_NAME.html.twig

<h3 class="accordion-header">{{ fields.title.content }}</h3>
<div class="accordion-content">{{ fields.body.content }}</div>

If I add:

{{  dump(fields.body.content) }}

Working version shows:

object(Drupal\Core\Render\Markup)[8515]
  protected 'string' => string '

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'views_view_field' -->
<!-- BEGIN OUTPUT from 'core/modules/views/templates/views-view-field.html.twig' -->
<p>Membership universal content</p>

<!-- END OUTPUT from 'core/modules/views/templates/views-view-field.html.twig' -->

Non-working version shows:

object(Drupal\Core\Render\Markup)[2061]
  protected 'string' => string '

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'views_view_field' -->
<!-- BEGIN OUTPUT from 'core/modules/views/templates/views-view-field.html.twig' -->
<p>&lt;p&gt;Membership universal content&lt;/p&gt;</p>

<!-- END OUTPUT from 'core/modules/views/templates/views-view-field.html.twig' -->

I have a work around by adding autoescape and convert_encoding

{% autoescape false %}

<h3 class="accordion-header">{{ fields.title.content }}</h3>
<div class="accordion-content">{{ fields.body.content|convert_encoding('UTF-8', 'HTML-ENTITIES') }}</div>

{% endautoescape %}

But this is now adding additional empty p tags before and after.

I don't understand why the output for one is escaped and the output for the other is not. Any pointers would be great, thank you.

2
  • The second output is the unprocessed field content, without text filters applied. See drupal.stackexchange.com/questions/238762/… how to apply them. Normally you wouldn't need to do this if the field is correctly configured in UI.
    – 4uk4
    Commented Mar 28, 2019 at 12:22
  • Hi @4k4 pulled my view apart and found the one with the escaping problem has aggregration on. With aggregation on , I have "<p>&lt;p&gt;Membership universal content&lt;/p&gt;</p>" with it off, I have "<p>Membership universal content</p>". In the body aggregation settings, included the format option and that fixed it. Thank you for your help.
    – ice70
    Commented Mar 29, 2019 at 15:51

1 Answer 1

3

the offending view also had aggregation enabled. To stop the escaped html, open the field's aggregation settings and include 'format'.

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.