Remove HTML Debug Comments from a particular field in debug mode

Created on 21 February 2016, over 8 years ago
Updated 16 February 2024, 9 months ago

The image is not displaying if debug mode is true because there is wrapper of html comments like following. So we do not need the wrapper for specific fields.

We need to
Change the code from

style="background:url(<!-- THEME DEBUG -->
<!-- THEME HOOK: 'views_view_field' -->
<!-- BEGIN OUTPUT from 'core/modules/views/templates/views-view-field.html.twig' -->
<!-- THEME DEBUG -->
<!-- THEME HOOK: 'image_url_formatter' -->
<!-- BEGIN OUTPUT from 'modules/contrib/image_url_formatter/templates/image-url-formatter.html.twig' -->
  http://local.oit-drupal8-new.com/sites/default/files/2016-01/id_banner_img.jpg

<!-- END OUTPUT from 'modules/contrib/image_url_formatter/templates/image-url-formatter.html.twig' -->
<!-- END OUTPUT from 'core/modules/views/templates/views-view-field.html.twig' -->)repeat"

to

style="background:url(http://local.oit-drupal8-new.com/sites/default/files/2016-01/id_banner_img.jpg)repeat"

🐛 Bug report
Status

Closed: outdated

Version

8.7 ⚰️

Component
Image module 

Last updated 10 days ago

Created by

🇮🇳India mukesh.dev

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • IMHO opinion this filter is needed, however it should target Twig specifically and properly process HTML entities.

    In its current form, the result is the same as |striptags|trim.

    For example, take a field value of "Twelve O'Clock".

    Both |striptags|trim and |remove_html_comments produce the same result:

    Twelve O&#039;Clock
    

    I suggest 2 changes to make this filter worthwhile in its own right:

    1. Rename it to |strip_twig_debug
    2. or

      |remove_twig_debug</li>
        <li>Process HTML entities</li>
      </ol>
      
      If processing HTML entities feels too invasive, you could always pass an optional argument allowing people to prevent HTML entity processing.
      
      Currently, the only viable option is the <a href="https://www.drupal.org/project/twig_htmlspecialchars_decode">twig_htmlspecialchars_decode</a> module, resulting in quite a long and clumsy filter chain  ':[]
      <code>
      |striptags|trim|twig_htmlspecialchars_decode
      
  • 🇳🇱Netherlands Martijn de Wit 🇳🇱 The Netherlands

    @camslice did you try the https://www.drupal.org/project/twig_field_value module?

  • 🇬🇧United Kingdom scott_euser

    You can also use https://www.drupal.org/project/twig_remove_html_comments which removes the html comments without removing the actual markup inside the nested template. I have suggested an update to the module homepage as it is outdated referencing this issue 📌 Module homepage description is in need of an update with incorrect information Active .

  • Status changed to Closed: outdated 9 months ago
  • 🇳🇿New Zealand quietone

    @scott_euser asked that the status of this issue be change to 'closed won't fix'.

    I have searched the issue and there is no commit here. I skimmed through the comments and do not see anything, like a documentation change, to suggest that this has been fixed. #36 closed this as outdated and the next comment changed the status to 'Fixed'. That was the mistake. If I know the issue where this was fixed there is a possibility that this could be closed as a duplicate and credit transferred. But, there is no reference to another issue so 'closed outdated' is the status to use.

    Also, noting that there are comments suggesting the use of contrib projects, #57, #58, #59

    I am restoring the status from #36

  • 🇬🇧United Kingdom scott_euser

    Thanks @quietone. In case people come across this issue because of debug comments added within formatted text, I separately raised 🐛 FilterAutoP should ignore twig.config debug html comments Needs review with a merge request proposing a solution.

Production build 0.71.5 2024