-
Notifications
You must be signed in to change notification settings - Fork 3
/
image.php
52 lines (45 loc) · 1.05 KB
/
image.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
use Kirby\Toolkit\Html;
/** @var \Kirby\Cms\Block $block */
$alt = $block->alt();
$caption = $block->caption();
$link = $block->link();
$img = null;
if ($block->location() === 'web') {
$img = Html::img($block->src(), ['alt' => $alt]);
} elseif ($image = $block->image()->toFile()) {
if ($alt->isEmpty()) {
$alt = $image->alt();
}
if ($caption->isEmpty()) {
$caption = $image->caption();
}
$img = Html::img(
$image->placeholderUri(),
[
'data-lazyload' => 'true',
'data-srcset' => $image->srcset(),
'data-sizes' => 'auto',
'width' => $image->width(),
'height' => $image->height(),
'alt' => $alt
]
);
} else {
return;
}
?>
<figure>
<?php if ($link->isNotEmpty()): ?>
<a href="<?= $link->toUrl() ?>">
<?= $img ?>
</a>
<?php else: ?>
<?= $img ?>
<?php endif ?>
<?php if ($caption->isNotEmpty()): ?>
<figcaption>
<?= $caption ?>
</figcaption>
<?php endif ?>
</figure>