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:
View Page preview:
View Page:
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:
Also a screenshot from my actual environment:
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.