Hugo: Add inline SVG support

Created on 25 Mar 2019  路  2Comments  路  Source: gohugoio/hugo

Inline SVGs can be styled with CSS. Is there already a way to inline SVGs in templates (and maybe also with a shortcode)?

This could be done with a partial, but is that the best way?

Most helpful comment

This could be done with a partial, but is that the best way?

An SVG can be inlined by using readfile (or a readfile shortcode). It may be necessary to change the width, height, id, and/or class attributes of the <svg> tag; or to wrap the element in a <div> with an id and/or class.

{{ readFile "/static/img/filename.svg" }}

All 2 comments

Please use https://discourse.gohugo.io/ for questions/troubleshooting. Also see Hugo Documentation.

This could be done with a partial, but is that the best way?

An SVG can be inlined by using readfile (or a readfile shortcode). It may be necessary to change the width, height, id, and/or class attributes of the <svg> tag; or to wrap the element in a <div> with an id and/or class.

{{ readFile "/static/img/filename.svg" }}
Was this page helpful?
0 / 5 - 0 ratings