A page with the URL appendix "product" already exists

Hi,

I received the above error when rendering a layout field in a template called product.php.

<section class="container">
    <?php foreach ($page->copy()->toLayouts() as $layout): ?>
        <div class="copy">
        <?php foreach ($layout->columns() as $col): ?>
            <?= $col->blocks() ?>
        <?php endforeach ?>
        </div>
    <?php endforeach ?>
</section>

Removing this code block from the template gets rid of the error. However, removing just the inner foreach loop isn’t enough.

This means, the error is triggered by the outer foreach loop:

<?php foreach ($page->copy()->toLayouts() as $layout): ?>
        // ...
<?php endforeach ?>

But what’s going on here? I don’t have another page with the same slug. Also, there’s no block snipped with the name product.

Could this be a bug?

For reference, this is the content of product.yml:

title: My Product
extends: layouts/default

tabs:
  content:
    label: Content
    fields:
      headline:
        label: Headline
        type: text
        width: 1/2
      subhead:
        label: Subhead
        type: text
        width: 1/2
      lead:
        label: Lead
        type: textarea

      copy:
        type: layout
        layouts:
          - "1/1"
          - "1/2, 1/2"
          - "1/3, 1/3, 1/3"

      images:
        Label: Images
        type: files
        min: 1
        uploads: image # template '/files/image'

Cheers,

Stefan

I was able to resolve the issue.

The problem was the filed name copy because $page->copy() is a built-in method that copies the page ($page->copy() | Kirby CMS).

In this case, this resulted in the “appendix … already exists” error.

After changing the field name to main, everything worked fine.

Cheers,

Stefan

You can also use $page->content()->copy() to always retrieve the field, even if a method with the same name exists in the core.

That’s good to know. Thank you!