Image in template


I have a template for my products, product.php, and I’d like Kirby to show an image of every product in the top area of the product page.

Every product has its own page and so its own folder, and in every folder I have a picture called “product.png” which shows the corresponding product.

What is the php-code for getting Kirby to display this “product.png”-image for each product?

Thank you!

So these product folders are children of a parent products folder?
Then you could do sth like this:

  foreach($page->children() as $child) :?>
  <img src="<?php echo $child->image('product.png')->url() ?>" >
<?php endforeach ?>

Thank you, Texnixe - sorry for not being more specific:

I don’t need to loop through the product images though because I’m not looking at a list or overview of products, but I’m looking at the display of a single individual product; so this code snippet will go into the “view product”-template, not the “product overview”-template.

Every product has in its folder next to other images a product image called “product.png”. I’d like to get a code snippet to put into my “view product”-template that tells Kirby to show this “product.png”-image.

I tried your code snippet by removing the “foreach”-part and put it into the template, but it didn’t work that way.

What’d be the correct code for this task?

I should be the same:

$image = $page->image('product.png');
<img src="<?php echo $image->url() ?>" >

If you only have one product image per product you need to display, you can also use the following to become independent from the file name:

$image = $page->images()->first();

Thank you! Works great - best regards.