1

I have a Drupal 8 site where we've created a view, and decided to use the summary field instead of the trimmed body field, so that we could have more control over it.

However, I got a bug report that the page had funny characters. When I looked, I found that a literal ampersand character, &, was changed to the HTML code &.

Thinking this was some weirdness introduced by our settings and configuration, I built a view on a clean install of Drupal 8.7.3 and generated some nodes with devel_generate. Sure enough, the ampersand HTML code appeared.

Node:

enter image description here

View Page preview:

enter image description here

View Page:

enter image description here

So, I want to get this to display a regular ampersand, as the user entered it.

I found this question explaining how to modify a twig template to use the raw value, but I'm not sure that's what I want to use. I don't want raw values for the whole field-- users could enter HTML in the summary field; I just want a non-encoded ampersand.

How do I get unencoded ampersands in the summary field in a view?

Edit leymannx recommended to uncheck Display any HTML as plain text on the text formats filter. However, both on my test fresh install and my real site, that filter is not checked, for any format.

I did my fresh install from downloading the Drupal core, and I think leymannx user composer, so I am going to try that, to see if I get the same behavior as he does. Also, I'm not going to install the devel modules to generate content, I'm just going to do one by hand.

These are screenshots from my fresh install:

enter image description here

enter image description here

Also a screenshot from my actual environment:

enter image description here

So, from those settings, it doesn't seem like the filter is what's causing this behavior.

Edit 2 I found something that I now suspect as perhaps the source of the error. The view on the fresh install is a view of files. I did not find the summary field in the list of fields, so I added a body field and re-wrote it with {{ body__summary }}. This is the config export yaml of the view I created.

2
+50

This is to confirm and clarify the issue according to my findings.
1. I was able to reproduce your findings by using a fresh Drupa 8.7.3 install and after importing your view in which you used the {{ body__summary }} rewrite.
enter image description here 2. I was able to reproduce the error by enabling Display any HTML as plain text option in Basic HTML text format.
3. I was also able to reproduce the error by rewriting the view field output and choosing {{ body__value }} which basically prints the raw value of the body field.

My opinion is that 2 & 3 are normal behavior and it should be expected that in these particular cases the raw HTML is displayed. However, in 1, it seems a bug because the summary shouldn't be displayed as raw HTML; it should follows the same rules as the selected format.
I suggest to open an issue in Drupal issue tracker telling them about 1; maybe there is a reason behind this behavior, or if somebody already knows the answer, please elaborate.

Regards

1

I couldn't reproduce this in a fresh Drupal 8 installation. Only after I went to configure the text format that's used for the body field and activated the "Display any HTML as plain text" filter the problem occurred. The body field and the summary field are sharing the same text format.

So, I'd suggest you simply disable this filter. And you should be fine. Text formats can be configured under https://example.com/admin/config/content/formats.

enter image description here


enter image description here

  • 1
    This is the correct answer. The summary field will use the same text format as the one the user selected for the body field. So just check the settings of this text format to ensure that HTML is not displayed as plain text. – misterdidi Jun 28 at 7:28
  • Can I ask how you stood up this fresh environment? Composer, drush site-install, etc.? I ask because my settings appear to be different from what you got out of the box. I'm editing my question to reflect this. – user1359 Jun 28 at 13:27
  • @user1359 – Just a default github.com/drupal-composer/drupal-project standard installation. I think "standard installation" is not any different no matter what way you gathered the installation files. (Bit outdated Drupal 8.6.10 – does this matter?) – leymannx Jun 28 at 13:50
  • @user1359 – Reproduced the same as in my answer with an up-to-date 8.7.3. So, Drupal version doesn't seem to matter. Somewhat must have activated this filter on your site somehow. – leymannx Jun 28 at 14:00
  • I wouldn't think it should matter, but I'm trying to figure out why your fresh install would be different from mine. The only thing I did on the fresh install was install the develop module, generate content, and create the view. I don't have "display ... as plain text" checked on any of the text formats. – user1359 Jun 28 at 14:14
1

I import your views and i did two changes and it works:

  1. Remove rewrite REWRITE RESULTS by unchecking Override the output of this field with custom text enter image description here
  2. Change Formatter from default to Summary or trimmed enter image description here
  3. The result. enter image description here

Output before enter image description here

Output after changes enter image description here

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.