I need a little advice to achieve a specific markup with the Kirby 3 panel. For a photo portfolio I want to have one to three images within a div to get several elements per page that look similar to this sketch:
What would be the nicest user-friendliest way to include that into Kirby 3? I already experimented with structure fields containing images but I got stuck with the blueprint syntax. If you tell me this is the way to go I’ll follow that route further …
Speaking in markup the result could be as simple as this:
The easiest was to do this is to use a single files field and then on front end use Css Grid to arange them in the desired layout. I do this on my own site:
Heres the code i use to drive that from the template, assuming you called the files field “gallery”:
<?php
$galleryimagesrc = $page->gallery()->toFiles();
$gallerycount = $galleryimagesrc->count();
?>
<section id="gallery" class="gallery-<?= $page->slug() ?>">
<?php if($gallerycount <= 1): ?>
<?php foreach($galleryimagesrc as $image): ?>
<!-- If there is only one image in the field -->
<?php endforeach ?>
<?php else: ?>
<div class="item-grid work-item-grid">
<?php foreach($galleryimagesrc as $image): ?>
<?php if($image->is($galleryimagesrc->first())): ?>
<div class="work-item">
<!-- Big First Image from the files field -->
</div>
<?php else: ?>
<div class="work-item">
<!-- From image 2 in the file field -->
</div>
<?php endif ?>
<?php endforeach ?>
</div>
<?php endif ?>
</section>
The if statement here is not necessary! With toFiles() you create a collection that can be empty or not, but if there are elements in the collection, they will exist.
You will probably check if your collection is empty or not to prevent rendering empty HTML tags.
Wow, thank you very much for those quick responses
Right now I have to take care of my favorite tiny human but tonight when she’s asleep I’ll be looking into adapting this solution for my project. I’ll let you know how it went