Add styles for the gallery
This commit is contained in:
23
site/snippets/blocks/gallery.php
Normal file
23
site/snippets/blocks/gallery.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/** @var \Kirby\Cms\Block $block */
|
||||
?>
|
||||
<figure class="gallery">
|
||||
<ul>
|
||||
<?php foreach ($block->images()->toFiles() as $image): ?>
|
||||
<li>
|
||||
<?php snippet('image', [
|
||||
'alt' => $image->alt(),
|
||||
'contain' => $block->crop()->isTrue(),
|
||||
'lightbox' => true,
|
||||
'ratio' => $block->ratio()->or('auto'),
|
||||
'src' => $image->url(),
|
||||
]) ?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php if ($block->caption()->isNotEmpty()): ?>
|
||||
<figcaption>
|
||||
<?= $block->caption() ?>
|
||||
</figcaption>
|
||||
<?php endif ?>
|
||||
</figure>
|
@@ -13,47 +13,32 @@
|
||||
https://getkirby.com/docs/guide/templates/snippets
|
||||
*/
|
||||
|
||||
$alt = $block->alt();
|
||||
$caption = $block->caption();
|
||||
$contain = $block->crop()->isFalse();
|
||||
$link = $block->link();
|
||||
$ratio = $block->ratio()->or('auto');
|
||||
$class = $ratio != 'auto' ? 'img' : 'auto';
|
||||
$src = null;
|
||||
$lightbox = $link->isEmpty();
|
||||
$src = null;
|
||||
|
||||
if ($block->location() == 'web') {
|
||||
$src = $block->src();
|
||||
$srcValue = $src->escape('attr');
|
||||
} elseif ($image = $block->image()->toFile()) {
|
||||
$alt = $alt->or($image->alt());
|
||||
$src = $srcValue = $image->url();
|
||||
if ($block->location()->value() === 'web') {
|
||||
$alt = $block->alt();
|
||||
$src = $block->src();
|
||||
} else if ($image = $block->image()->toFile()) {
|
||||
$alt = $block->alt()->or($image->alt());
|
||||
$src = $image->url();
|
||||
}
|
||||
|
||||
if ($ratio !== 'auto') {
|
||||
$ratio = Str::split($ratio, '/');
|
||||
$w = $ratio[0] ?? 1;
|
||||
$h = $ratio[1] ?? 1;
|
||||
}
|
||||
|
||||
$attrs = attr([
|
||||
'class' => $class,
|
||||
'data-contain' => $contain,
|
||||
'data-lightbox' => $lightbox,
|
||||
'href' => $link->or($src),
|
||||
'style' => '--w:' . $w . '; --h:' . $h,
|
||||
]);
|
||||
|
||||
?>
|
||||
<?php if ($srcValue): ?>
|
||||
<?php if ($src): ?>
|
||||
<figure>
|
||||
<a <?= $attrs ?>>
|
||||
<img src="<?= $srcValue ?>" alt="<?= esc($alt, 'attr') ?>">
|
||||
</a>
|
||||
|
||||
<?php if ($caption->isNotEmpty()): ?>
|
||||
<?php snippet('image', [
|
||||
'alt' => $alt,
|
||||
'contain' => $block->crop()->isFalse(),
|
||||
'lightbox' => $block->link()->isEmpty(),
|
||||
'href' => $block->link()->or($src),
|
||||
'src' => $src,
|
||||
'ratio' => $block->ratio()->or('auto')
|
||||
]) ?>
|
||||
|
||||
<?php if ($block->caption()->isNotEmpty()): ?>
|
||||
<figcaption class="img-caption">
|
||||
<?= $caption ?>
|
||||
<?= $block->caption() ?>
|
||||
</figcaption>
|
||||
<?php endif ?>
|
||||
</figure>
|
||||
|
Reference in New Issue
Block a user