Reading svg files from plugin assets

I do have a strange behavior while loading svg files from my own theme-plugin. I can open the files in the browser, the url is correct. But reading them with svg() or asset()->read() seams like a gambling. Sometime it’s working, sometimes not. Seams like a caching problem but I did’t activate caching. Any idea? Thx.

How are you accessing the file? could you post your code?

Of course … for example this one works exactly in one blocks-snippet but not in another.

<?= svg('media/plugins/myname/plugin-name/img/icons/icon_xyz.svg') ?>

I also tried this, but same behavoir…

<?= asset('media/plugins/myname/plugin-name/img/icons/icon_accordion.svg')->read() ?>

Thx for helping.

Ok I may habe something. The svg doesn’t exists in the media folder, that’s why it can’t be read. When I open the svg directly in the browser, the file will be created in the media folder.


The media folder is always in a state of flux

Give this a shot

<?= svg($kirby->root('plugins').'/plugin-name/img/icons/icon_xyz.svg') ?>

But consider if you need these as files at all. These seem like little icons, which might be better off as Base64 in the stylesheet.

yes, thats by design. once you successfully access something, it ends up in the media folder.

To be honest i have never made a plugin that has some assets, but the line of code above will fetch the file from the plugins folder, rather then the media folder. Im not :100: sure thats the right way or not :slight_smile:

Thank you @jimbobrjames, I will give it a shot and let you know. I would have thought by implement it with svg() it would also end up in the media folder.

I would like to integrate all svgs into the html file rather then convert them all to base64 into stylsheet. This is easier with css manipulation, but I see your point as well.

Yeah mee, too. This is the first time I try to throw all template/theme related files into an own plugin :slight_smile:

This works for me. If somebody has a better/cleaner solution, I would like to hear. But for now, I’m happy with this one. Thx again @jimbobrjames.