Hey,
I’m building a site using Kirby Builder. I have created a builder field called ‘twoup’ which sits in the blueprint like so:
twoup:
label: Two-up
snippet: panel/twoup
fields:
left:
label: Left image
type: image
right:
label: Right image
type: image
I’m trying to dynamically style the two images side by side depending on whether their orientation is landscape / portrait / or a mixture of both using this code:
<?php
// Store as variables
$left = $page->image($data->left());
$right = $page->image($data->right());
// Check if the images exist
if($left and $right):
?>
<?php if($left->isLandscape() and $right->isLandscape()): ?>
<!-- Two-up hori -->
<div class="section bordered">
<div class="twoup-hori">
<img src="<?= $left->url() ?>">
<img src="<?= $right->url() ?>">
</div>
</div>
<?php elseif($left->isPortrait() and $right->isPortrait()): ?>
<!-- Two-up vertical -->
<div class="section bordered">
<div class="twoup-vert">
<div class="half-col">
<img class="float-right" src="<?= $left->url() ?>">
</div>
<div class="half-col">
<img class="float-left" src="<?= $right->url() ?>">
</div>
</div>
</div>
<?php else: ?>
<!-- Two-up mixed -->
<?php if ($left->isNotEmpty() and $right->isNotEmpty()): ?>
<div class="section bordered">
<div class="twoup-mixed">
<div class="half-col">
<img class="float-right" src="<?= $left->url() ?>">
</div>
<div class="half-col">
<img class="float-left" src="<?= $right->url() ?>">
</div>
</div>
</div>
<?php endif ?>
<?php endif ?>
<?php endif ?>
But everytime I try to add a ‘twoup’ builder to the panel it breaks the site with a “_toString must not throw an exception” error and I have to comment out the twoup builder field and delete the offending fieldset in order to bring the site back. I have checked if the images exist before running the code – where am I going wrong? Any help much appreciated!
