Is it possible to inlcude code from a svg file directly into a twig template file?
Something like:
{% include 'my.svg' %}
that will result in:
<svg viewbox=".... />
One simple way using Twig There's a very simple way to do it using Twig! Simply use the source function in your template. This will copy the text present in the SVG file and put it in your generated HTML, thus make it a proper recursive and editable DOM element. That's it!
Scalable Vector Graphics (SVG) is a web-friendly vector file format. As opposed to pixel-based raster files like JPEGs, vector files store images via mathematical formulas based on points and lines on a grid.
In case of theme it's good option to use {{ directory }}
variable that holds path to theme.
{{ source(directory ~ '/images/my.svg') }}
One way of doing this:
{{ source('my.svg') }}
Read more here: https://www.theodo.fr/blog/2017/01/integrating-and-interacting-with-svg-image-files-using-twig/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With