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

Closed
missmatsuko opened this issue Jul 26, 2019 · 1 comment

Comments

@missmatsuko
Copy link
Contributor

commented Jul 26, 2019

Description

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.

@brandonkelly

This comment has been minimized.

Copy link
Member

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: https://github.com/craftcms/cms/blob/3.3/docs/dev/filters.md#attr

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