Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The Views field Global > Custom text is escaping HTML despite the fact that the description of the field says
You may include HTML or Twig
If you enter the value:
<a href="http://example.com">Example</a>
It will be rendered as:
<a href="http://example.com">Example</a>
This is a regression caused by:
#2348729: Convert theme_views_view_field to twig
https://www.drupal.org/node/2348729#comment-10358601
A temporary workaround is in comment #4
Comment | File | Size | Author |
---|---|---|---|
#13 | views-2584655-double-escape-13.patch | 367 bytes | samuel.mortenson |
#5 | output-view.png | 93.4 KB | charlieweb82 |
Comments
Comment #2
dawehnerWhat have you chosen as input for this field? I think in general providing an export of the configured view could be really helpful.
Comment #3
heykarthikwithu"Global: Custom text" is the input field chosen, have a look at the exported view, may get an clue.
Comment #4
turegjorup CreditAttribution: turegjorup commentedI'm seeing this as well after upgrading to RC1. Didn't experience the issue with beta16. Copying the core views-view-field-html.twig template to my theme and adding the raw filter eg. {{ output | raw }} fixes it.
Checking the diff for the core template between beta16 and RC1 is that {{ output }} has been changed to {{ output -}}. However removing the "-" isn't enough to fix it that requires the raw filter. So I'm thinking there must be some other change the rendering of "Custom text" in views between beta16 and RC1.
Comment #5
charlieweb82 CreditAttribution: charlieweb82 commentedYes is correct in beta16 work fine, only in the RC1 is the issues here the view and a screenshot of the output
Comment #6
charlieweb82 CreditAttribution: charlieweb82 commentedthe solution you mention @turegjorup is good, fix the problem and render the output I add the views-view-field-html.twig to my theme templates and add the {{ output | raw }} and the custom field render the fields in the view. but this need a fix in other version.
Comment #7
Devline CreditAttribution: Devline commentedThe issue is also occuring since RC1, on text replacement when the field is empty. It's working fine for the primary text replacement (when the field is not empty). Fix from @turegjorup is ok for temporary workaround.
Comment #8
tannerjfco CreditAttribution: tannerjfco commentedThis is a regression, so I think major is appropriate.
Comment #9
dawehnerNote: We also work on the dev version, never on the RC1 itself :)
Comment #10
dalinThe offending patch appears to have been:
#2348729: Convert theme_views_view_field to twig
https://www.drupal.org/node/2348729#comment-10358601
Comment #11
dalinComment #12
dalinComment #13
samuel.mortensonI think outputting as raw is appropriate here, although it does looks weird in a core template. From what I can tell, all the output being sent to views-view-field.html.twig has already been passed through a Views field plugin's advancedRender method, which manually renders (and escapes when appropriate) fields. I'm not an expert on how this particular render pipeline works, so we'll need to review this to make sure this is not a security risk.
Comment #14
lauriii#2579427: Outputting markup from custom text field is not possible is RTBC