I am rewriting the results of a field in a View and depending on the value of a field, I want to display an SVG icon. I can use TWIG to do the conditional logic and that works great, but it won't let me use the SVG tag. There is help text below that says:

You may include Twig or the following allowed HTML tags: <a> <abbr> <acronym> <address> <article> <aside> <b> <bdi> <bdo> <big> <blockquote> <br> <caption> <cite> <code> <col> <colgroup> <command> <dd> <del> <details> <dfn> <div> <dl> <dt> <em> <figcaption> <figure> <footer> <h1> <h2> <h3> <h4> <h5> <h6> <header> <hgroup> <hr> <i> <img> <ins> <kbd> <li> <mark> <menu> <meter> <nav> <ol> <output> <p> <pre> <progress> <q> <rp> <rt> <ruby> <s> <samp> <section> <small> <span> <strong> <sub> <summary> <sup> <table> <tbody> <td> <tfoot> <th> <thead> <time> <tr> <tt> <u> <ul> <var> <wbr>

So as you can see, SVG is not there. Is there a way to make it allowable?

1 Answer 1


You can get around it by doing the overriding via template file rather than views config.

If you would like to allow it on views config and as long as you feel comfortable that non of your admins will do any evil XSS using svg to seek higher admin power and take over the world site, you could patch https://github.com/drupal/core/blob/9.3.x/lib/Drupal/Component/Utility/Xss.php#L21.

  • This did indeed work. THANKS
    – Erich H.
    Commented Dec 30, 2021 at 23:41

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.