Adding a custom SVG to a plugin

AI-generated summary

The discussion revolves around adding a custom SVG icon to a Discourse plugin. Alteras initially sought guidance, noting that documentation seemed limited to themes and that register_svg_icon appeared to be for Font Awesome icons. awesomerobot clarified that register_svg_icon supports any SVG, explaining the need to place the SVG in a spritesheet (e.g., svg-icons/sprite.svg) with a unique ID, following the same process as theme customization. They also provided the correct syntax in plugin.rb: register_svg_icon "my-svg-id". Alteras confirmed the method worked and asked if the server could automatically detect SVG changes, noting the inconvenience of manual page and dev server refreshes after edits.

I am looking to add a custom SVG icon to a plugin I am working on, but couldn’t find any documentation or topics on how to do so. All the documentation seems to be on doing it for a theme.

The register_svg_icon function seems to be only for FA icons, based on other plugin repos I’ve seen.

I imagine I can probably just put the SVG inside the public folder and pull it like a normal image, but I’d like to avoid it as a last resort.

register_svg_icon will work for any SVG, it isn’t specific to Font Awesome

So you’d add a new sprite with your icon, like svg-icons/sprite.svg — the guidance on the spritesheet is the same as Replace Discourse's default SVG icons with custom icons in a theme (so make sure to set an id)

Then in plugin.rb you can do:

register_svg_icon "my-svg-id"

It works! Thank you!

I don’t suppose there’s a way to have the server watch for changes to the SVG file? Its a very minor inconvenience to refresh the page (and sometimes the dev server itself) every time I change the SVG.