statamic / ideas

💡Discussions on ideas and feature requests for Statamic
https://statamic.dev
30 stars 1 forks source link

Add the ability to pass variables into an SVG tag #1022

Closed JayGeorge closed 11 months ago

JayGeorge commented 11 months ago

It would be great if we could pass variables to an SVG tag, like this:

{{ svg src='logo' some_var='1' }}

Then inside the SVG: <title id="logo-{{ some_var }}">

Background/Context

Making an SVG accessible involves adding unique Title and Description IDs for screen readers, like this:

<title id="uniqueTitleID">The title of the SVG</title>
<desc id="uniqueDescID">A longer, more complete description for complex graphics.</desc>

(source)

This is easy but if you try to use the same SVG more than once on a page (quite often happens when using SVG "icons"), if you run your site through a validator then you'll get an error like this: Duplicate ID validation error, since every SVG title and description needs to be unique.

It would be handy to be able to do something like this in order to mitigate this:

{{ svg src='logo' index='1' }}

Then inside the SVG: </p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/jasonvarga"><img src="https://avatars.githubusercontent.com/u/105211?v=4" />jasonvarga</a> commented <strong> 11 months ago</strong> </div> <div class="markdown-body"> <p>The svg tag has <code>title</code> and <code>desc</code> parameters you can use. It was added in 3.3.66 <a href="https://github.com/statamic/cms/pull/7348">https://github.com/statamic/cms/pull/7348</a> But were never documented, sorry we'll get on that.</p> <pre><code class="language-antlers">{{ svg src="logo" title="something" desc="something" }}</code></pre> <p>But I'm now seeing that you also want title and desc to have ids. And probably <code>aria-labelledby="uniqueTitleID uniqueDescID"</code> on the svg itself?</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/JayGeorge"><img src="https://avatars.githubusercontent.com/u/693601?v=4" />JayGeorge</a> commented <strong> 11 months ago</strong> </div> <div class="markdown-body"> <blockquote> <p>The svg tag has title and desc parameters you can use.</p> </blockquote> <p>Ah great, that does help a lot!</p> <blockquote> <p>But I'm now seeing that you also want title and desc to have ids. And probably aria-labelledby="uniqueTitleID uniqueDescID" on the svg itself?</p> </blockquote> <p>Actually, reading the CSS-Tricks article more carefully, those extra things were something that was needed a while back to get around browser bugs, but it looks like Chrome and Firefox have fixed those bugs now.</p> <p>So I think that's solved!</p> </div> </div> <div class="page-bar-simple"> </div> <div class="footer"> <ul class="body"> <li>© <script> document.write(new Date().getFullYear()) </script> Githubissues.</li> <li>Githubissues is a development platform for aggregating issues.</li> </ul> </div> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script> <script src="/githubissues/assets/js.js"></script> <script src="/githubissues/assets/markdown.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/go.min.js"></script> <script> hljs.highlightAll(); </script> </body> </html>