Read the content of an asset

I’ve got an SVG in my assets folder. I would like to be able to echo the actual markup that is in that file as opposed to just throwing the SVG into an <img />. I would like to do this so that I can manipulate the SVG with CSS.

I can put the SVG in a snippet called “logo.php” and load it in like this: <?php snippet("logo"); ?> but I prefer to have my images in the actual assets folder. Is there any way I can read the contents of an asset?

I was hoping I could use something like:

<?php url('assets/images/move-this-logo.svg')->read(); ?>

But of course this doesn’t work because read() doesn’t know what to do with a string. Any help would be greatly appreciated!

You can use f::read()

<?= f::read('assets/images/move-this-logo.svg'); ?>

Well that is frustratingly simple! I’ve been banging my head against the wall here for a little bit and didn’t come across that.

I see now that it’s in the API docs (I’ve been spending most of my time with the Cheat Sheet). Thanks for your speedy reply!

1 Like