Include SVGs inline in themes
1
If you would like to include inline SVGs in your theme templates then you can do the following:
- Create a partial called include-svg.htm and put the following code in it:
== <?php function onStart() { $this['svgContents'] = File::get(base_path($this->file)); } ?> == {{ svgContents|raw }}
- Include your desired SVG like so:
{% partial "include-svg" file="themes/mytheme/assets/images/mysvg.svg" %}
Looks very handy. Does that mean one less network request for each SVG using this partial?
I just copy paste the svg code into a partial "mysvg.htm" and include its with {% partial "mysvg.htm" %}.
Works very nice too, no network request too, but perhaps not such a clean solution :)