We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Grav 1.7: Example Twig: {{svg_image("/user/pages/img/image.svg", "h-24 w-auto")}}
{{svg_image("/user/pages/img/image.svg", "h-24 w-auto")}}
Expected behaviour: css classes are attached to the SVG tag
Actually happening: classes being applied to all subtags (paths etc) but not the SVG tag
Problem: In the current twig function svgImageFunction() the regex matches the whole svg file instead of the SVG tag alone for the replacement
Solution: Replace in Line 1440 of TwigExtension.php with this code:
$svg = preg_replace_callback('/^<svg[^>]*(class=\")([^"]*)(\")[^>]*>/', function($matches) use ($classes, &$matched) { if (isset($matches[2])) { $new_classes = $matches[2] . $classes; $matched = true; return str_replace($matches[1], "class=\"$new_classes\"", $matches[0]); } return $matches[0]; }, $svg );
The text was updated successfully, but these errors were encountered:
Fix Twig svg_image() issue with classes applied to all elements #3068
svg_image()
1c63f4b
rhukster
No branches or pull requests
Grav 1.7:
Example Twig:
{{svg_image("/user/pages/img/image.svg", "h-24 w-auto")}}
Expected behaviour: css classes are attached to the SVG tag
Actually happening:
classes being applied to all subtags (paths etc) but not the SVG tag
Problem:
In the current twig function svgImageFunction() the regex matches the whole svg file instead of the SVG tag alone for the replacement
Solution:
Replace in Line 1440 of TwigExtension.php with this code:
The text was updated successfully, but these errors were encountered: