Hello,
Is there is a way to use the kirby 3 gallery plugin (the one in the starter kit)
but with images coming not from an other category (photography pages in the starter kit),
but with the files of the page ?
Thank you for your help
Hello,
Is there is a way to use the kirby 3 gallery plugin (the one in the starter kit)
but with images coming not from an other category (photography pages in the starter kit),
but with the files of the page ?
Thank you for your help
Not as is, because the plugin handles the special case that you select a page in the gallery field and then the images of the selected page are fetched to create the gallery.
But you can write your own plugin that does what you want.
<?php
Kirby::plugin('starterkit/gallery', [
'hooks' => [
'kirbytags:after' => function ($text, $data, $options) {
if (($page = $data['parent']) && $page->hasImages()) {
$gallery = snippet('gallery', ['gallery' => $page], true);
} else {
$gallery = '';
}
return str_replace('{{ gallery }}', $gallery, $text);
}
]
]);
If you change it like this, it would fetch the images of the current page instead.
Thanks a lot for your answer.
Is it possible to select a set of images from a field ?
gallery:
headline: gallery
type: files
multiple: true
info: "{{ page.images.count }} image(s)"
empty: "no gallery"
image:
query: page.image
cover: true
That’s doesn’t seem to be a field, but a section, so no, you can’t fetch anything from that. If you assign a template to that files section, you could filter your files by that template in the gallery snippet. Or is that a in fact a field and you just using the headline
property by mistake?
If you post your complete blueprint, that would help.
I put the blueprint below.
The idea is for the user to have the possibility to add selected files of the page into a gallery.
title: Projet
num: date
status:
draft:
label: Draft
text: The note is still in draft mode. It can only be seen by editors with panel access.
unlisted:
label: In Review
text: The note is online and can be visited with the direct URL. The team must still give the final go to publish it.
listed:
label: Published
text: The note is online and listed in the blog
columns:
- width: 2/3
sections:
infos:
type: fields
fields:
intro:
label: Introduction
type: textarea
size: small
text:
label: Texte
type: textarea
size: large
- width: 1/3
sections:
meta:
type: fields
fields:
business:
label: Business
type: text
designer:
label: Designer
type: text
date:
type: date
time: false
default: now
format: YmdHi
cover:
headline: The cover image
template: cover
type: files
document:
type: files
layout: list
info: "{{ file.size }}"
image:
query: page.image
cover: true
ratio: 5/4
gallery:
headline: gallery
type: files
multiple: true
info: "{{ page.images.count }} image(s)"
empty: "no gallery"
image:
query: page.image
cover: true
Ah, ok, that is indeed a files field (please note that fields have labels, not headlines).
The let’s do it like this:
Kirby::plugin('starterkit/gallery', [
'hooks' => [
'kirbytags:after' => function ($text, $data, $options) {
$images = $data['parent']->gallery()->toFiles();
if ($images->isNotEmpty()) {
$gallery = snippet('gallery', ['images' => $images], true);
} else {
$gallery = '';
}
return str_replace('{{ gallery }}', $gallery, $text);
}
]
]);
And the gallery.php
snippet:
<section class="gallery">
<?php foreach ($images as $image): ?>
<figure>
<a href="<?= $image->link()->or($image->url()) ?>">
<?= $image->crop(600, 800) ?>
</a>
</figure>
<?php endforeach ?>
</section>
Thanks a lot texnixe !