htmlcssshopifyliquid

Shopify Liquid Filter to insert SVG file straight in HTML?


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>

Solution

  • You can now directly output the contents of an SVG file (or CSS or JS file) in your theme assets directory using the inline_asset_content HTML filter. Docs @ https://shopify.dev/docs/api/liquid/filters/inline_asset_content.

    Usage: {{ 'icon.svg' | inline_asset_content }}