I am trying to understand the svg() helper. Is it supposed to render a valid
Nothing happens when I use it this way in my template:
<?php svg($site->file('mysvg.svg')) ?>
<?= svg($site->file('mysvg.svg')) ?>
Any help appreciated,
svg() helper takes an absolute or relative path as parameter. You are passing a File object.
thanks @texnixe and @bnomei
<?php echo svg($site->file('myfile.svg')->root()) ?>
<?php echo svg($site->file('myfile.svg')->url()) ?>
but nothing gets rendered.
Even when I use the explicit path/url of the SVG, as @texnixe suggested, nothing gets rendered in my HTML. The console shows no error either.
The svg helper only accepts a path, not the root or anything like that, so something like
echo svg('content/'.$site->image('my file.svg')->filename());
works for me, and getting a file from the assets folder like outlined above.
I can’t find a File method that returns the relative path
But to achieve the same as what the
svg() helper does, you might as well just do this:
if($image = $site->file('myfile.svg')):
both of your proposals work now as expected
I will stick with the
$image->read() method, as it feels more straightforward to me.
but I would suggest to update the
svg() docs (when there is some time left ) because I assume other people will be confused, too.
or a short cookbook episode showing the use of image files in templates in general?
for me SVGs are crucial elements of websites as I use thsi format for all icons and even some logos.