My logo should link to my homepage. For now I just want to use a relative link. I currently have
<div class="logo"><a href="index"><img src="xyz-logo.svg"</a></div>
but when I click on the logo it takes me to the error page
My logo should link to my homepage. For now I just want to use a relative link. I currently have
<div class="logo"><a href="index"><img src="xyz-logo.svg"</a></div>
but when I click on the logo it takes me to the error page
Probably just a /
But again, the right way to do it:
<div class="logo"><a href="<?= $site->url() ?>"><img src="xyz-logo.svg"</a></div>
I really think it makes sense to start doing things “the Kirby way” right from the beginning. It’s also the best way to learn.
I guess writing
<img src="/assets/images/logo.svg" alt="some text">
will not work if I put my Kirby site on a sub-folder of my live website. And that there is a Kirby way of doing this which will ensure the image displays wherever the website is.
So I’ve tried doing this, but get a PHP error:
<?= image('assets/images/logo.svg')->url() ?>I’m guessing, because the logo file is outside of the Kirby Content folder - it is in the assets folder - it can’t find the url of the image, nor does the file have alt text.
So I’ve tried the following:
<img src="<?= url('/assets/images/logo.svg') ?>" alt="name of business">
This works. I’ve read other ways of doing this, but I don’t understand them. Can I just use the above?
Yes, that’s fine.
An alternative would be to use the asset()
helper (the image()
helper only works for files inside the /content
folder:
<img src="<?= asset('assets/images/logo.svg')->url() ?>" alt="name of business">
(in safe code, this would of course again go inside an if statement)
Another option would be to actually use the svg in your html instead of passing it its url as src attribute to the image element:
<?= svg('assets/images/logo.svg') ?>
(So use this without img element)
Thank you!
How come you’re always on here? Amazing!
I’m a bot