-
Notifications
You must be signed in to change notification settings - Fork 641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Add "title" argument to Twig svg() function #3937
Comments
I could envision a more general |
Closing this in favor of #4660 |
Turns out there was a use case for custom elements. Also some cleanup and docs for the new $elements functionality.
Sorry, just realized this is referring to a |
Just added new {{ svg('@webroot/icons/wave.svg')
|append('<title>Waving Hand</title>')
|append('<desc>A waving hand icon.</desc>') }} If you think the SVG may already contain
{{ svg('@webroot/icons/wave.svg')
|append('<title>Waving Hand</title>', 'keep')
|append('<desc>A waving hand icon.</desc>', 'replace') }} I’ve also added a new {{ svg('@webroot/icons/wave.svg')
|append(tag('title', {text: 'Waving Hand'}), 'keep')
|append(tag('desc', {text: 'A waving hand icon.'}), 'replace') }} You can combine these new filters with the new {{ svg('@webroot/icons/wave.svg')
|attr({role: 'img', 'aria-labelledby': 'title desc'})
|append(tag('title', {id: 'title', text: 'Waving Hand'}), 'replace')
|append(tag('desc', {id: 'text', text: 'A waving hand icon.'}), 'replace') }} Or even move all this into a custom macro: {% macro accessibleSvg(svg, title, desc) %}
{%- set ns = 'svg' ~ random() %}
{{- svg(svg)
|attr({role: 'img', 'aria-labelledby': "#{ns}-title #{ns}-desc"})
|append(tag('title', {id: "#{ns}-title", text: title}), 'replace')
|append(tag('desc', {id: "#{ns}-desc", text: desc}), 'replace') }}
{%- endmacro %}
{{ _self.accessibleSvg(
'@webroot/icons/wave.svg',
'Waving Hand',
'A waving hand icon.'
) }} |
Very cool! 👍 |
The
<title>
tag of an<svg>
can be used to provide alternative text for accessibility reasons. It would be nice if we could add/replace the<title>
tag when inlining SVGs with thesvg()
function in Twig. Sometimes the same icon can mean different things depending on the context, or on a multilingual site you may want to translate it.The text was updated successfully, but these errors were encountered: