Panel breaks with Kirby Builder: "_toString must not throw an exception"

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!

Solved – Sorry all: seems as though my snippets that I had created for previewing the blocks in the panel used deprecated fields.

Check those snippets!!!

Good to hear you solved your problem, but nevertheless this line:

doesn’t make sense. $left and $right are defined as images, so you can’t check if these are empty or not. isNotEmpty() is a field method, not a file method. Since you have already checked if you have images, you don’t need any additional condition here anymore, unless you maybe wanted to check something else?

Good spot Texnixe. Thank you! You’re always here when I need you :slight_smile: