Skip to content
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

Add any attributes with svg() #4660

missmatsuko opened this issue Jul 26, 2019 · 1 comment


Copy link

commented Jul 26, 2019


We can already add classes to SVGs with this function, but it would be great if we could add any attribute.

It would make it a lot easier to follow accessible SVG patterns, especially with #3937 and if there were some way to reference the title and/or desc elements added that way.


This comment has been minimized.

Copy link

commented Aug 18, 2019

Just added a new |attr filter for Craft 3.3, which will work on any HTML element, not just SVGs.

{{ svg('@webroot/icons/wave.svg')|attr({
    class: 'icon',
    role: 'img',
    'aria-labelledby': 'title  desc'
}) }}

It supports the same attribute definition as the attr() function added in 3.2 – they both use Html::renderTagAttributes() behind the scenes.

Docs here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.