A unique scenario popped up recently during a project I am building with Aurelia. I needed to cleanly be able to insert SVG images from a folder in my app and display them inline. Duplicating the SVG’s and inlining them was an option, or creating a custom element seemed like a better choice.
What I ended up coming with is the rather simple, but elaborate looking custom element which essentially replaces itself with the contents of an SVG.
To use it, all you need to do is import the inline-svg
class and then in your HTML view: <inline-svg svg="icons/heart.svg"></inline-svg>
you might want to change the path in the above example if you’re not always loading SVG’s from an images folder.
If you are not using TypeScript (like the above example) you will want to change it to be conventional Javascript instead of copying and pasting the above as is.
Interesting. So, if you had an icon that was used several times on a page, let’s say a heart or thumbs up to react to a post or something, the SVG would be added for each instance, correct? In this case, using something like “SVG Store” to combine and create symbols may be the better way to go.