Is there a filter to stick an SVG file right in the HTML of a Liquid file? I want to be able to manipulate the SVG styling with CSS, which I am unable to do if I only set the SRC
of an IMG
.
For example, is something like this possible with Shopify Liquid:
{{ 'file.svg' | file_url | svg_filter }}
compiles to
<svg>blablalba</svg>
3
Answers
Nope there is no filter but you can “hack” it to show it’s html.
If you make a fetch request to the SVG url and it will return it’s contents and you can append the content on your page.
While this is not a great solution it’s something.
Example:
I would recommend instead that you put all of your svgs into one liquid snippet file like this:
Then you can call it like this:
{% render 'icon' with 'down' %}
Which is the equivalent of calling it like this:
{% render 'icon', icon: 'down' %}
I use the below to add svg images into liquid files.
{{ 'file.svg' | asset_url | img_tag }}