xiaowang/kirby/config/blocks/image/image.php

36 lines
860 B
PHP
Raw Normal View History

2021-10-29 18:05:46 +02:00
<?php
/** @var \Kirby\Cms\Block $block */
$alt = $block->alt();
$caption = $block->caption();
$crop = $block->crop()->isTrue();
$link = $block->link();
$ratio = $block->ratio()->or('auto');
$src = null;
if ($block->location() == 'web') {
2022-08-31 16:08:03 +02:00
$src = $block->src()->esc();
2021-10-29 18:05:46 +02:00
} elseif ($image = $block->image()->toFile()) {
2022-08-31 16:08:03 +02:00
$alt = $alt ?? $image->alt();
$src = $image->url();
2021-10-29 18:05:46 +02:00
}
?>
<?php if ($src): ?>
2022-08-31 16:08:03 +02:00
<figure<?= Html::attr(['data-ratio' => $ratio, 'data-crop' => $crop], null, ' ') ?>>
2021-10-29 18:05:46 +02:00
<?php if ($link->isNotEmpty()): ?>
2022-08-31 16:08:03 +02:00
<a href="<?= Str::esc($link->toUrl()) ?>">
2021-11-18 17:44:47 +01:00
<img src="<?= $src ?>" alt="<?= $alt->esc() ?>">
2021-10-29 18:05:46 +02:00
</a>
<?php else: ?>
2021-11-18 17:44:47 +01:00
<img src="<?= $src ?>" alt="<?= $alt->esc() ?>">
2021-10-29 18:05:46 +02:00
<?php endif ?>
<?php if ($caption->isNotEmpty()): ?>
<figcaption>
<?= $caption ?>
</figcaption>
<?php endif ?>
</figure>
<?php endif ?>