I’m following Bastian’s videos to learn KirbyCMS and trying to recreate a list of brands I worked with to display in my website.
Everything works well, but I’d like to get the SVG path of the image so that I can style them via CSS.
What I did so far:
In content/5_brands
I have all the svg images.
I followed the snippet and controller approach, so I have:
Controller:
// controllers/brands.php
<?php
return function ($page) {
$brands = $page->images()->filterBy('extension', 'svg');
return [
'brands' => $brands
];
};
Snippet:
<!-- snippets/brands.php -->
<ul class="brands">
<?php foreach ($brands as $brand): ?>
<li>
<figure>
<img src="<?= $brand->url() ?>" />
</figure>
</li>
<?php endforeach ?>
</ul>
Template:
<?php snippet('header') ?>
<?php snippet('navigation') ?>
<?php snippet('breadcrumb') ?>
<div class="container">
<h3><?= $page->title() ?></h3>
<p> <?= $page->text()->markdown() ?></p>
</div>
<?php snippet('brands') ?>
<?php snippet('footer') ?>
I the video related to SVG, Bastian is using asset( )
but I cannot get the path.
I tried another approach for the snippet but still does not work:
<ul class="brands">
<?php foreach ($brands as $brand): ?>
<li>
<figure>
<svg viewBox="0 0 100 100">
<path d="<?= $brand->svgPath() ?>" />
</svg>
</figure>
</li>
<?php endforeach ?>
</ul>
What I can do to get the path in the snippet?
A second related question is that my approach currently is to create a brand page to test this, and my idea is to reuse the snippet is the homepage of the website.
Is it correct to have the brands like I did inside content/5_brands
? Or semantically is better to have them in the asset folder?
I’m trying to use the snippet from the home page with this code:
<?php snippet('brands', [
'brands' => page('brands')
->children()
]) ?>
And the no errors so far, but svg/brand are not listed.
Thanks for any help.