Restaurant Menu reproduce

Hello,

I want to adapt this structure (https://getkirby.com/docs/reference/panel/samples/menu) for my project. I don’t know why I don’t start.

blueprints/pages/links.yml

    title: Links
    icon: 🍕

    fields:
      namepage:
        label: 
          en: Real Page Name
          fr: Nom de page
        type: text

      text:
        label: 
          en: Intro
          fr: Intro
        type: textarea
        size: normal

      links_carolefredericks:
        extends: fields/links
        label: Carole Fredericks

      links_musicwebsite:
        extends: fields/links
        label: Music Websites

      links_tvshowwebsites:
        extends: fields/links
        label: TV show Websites

      links_blogs:
        extends: fields/links
        label: Blogs

      links_misc:
        extends: fields/links
        label: Misc

/site/blueprints/fields/links.yml

    label: Category
    type: structure
    fields:
      links_title:
        label: 
          en: Title
          fr: Titre
        type: text
      links_description:
        label: 
          en: Description
          fr: Description
        type: textarea
      links_url:
        label: URL
        type: url
      url_lang:
        label:
          en: Lang
          fr: Langue
        type: checkboxes
        options:
          - English
          - French
          - Others

/controllers/links.php

    <?php
    return function () {
        $categories = [
            'Carole Fredericks',
            'Music Websites',
            'TV show Websites',
            'Blogs',
            'Misc'
        ];
        return [
            'categories' => $categories
        ];
    };

templates/link.php

<?php snippet('header') ?>`
    <main class="restaurant-menu">
      <header class="intro">
        <h1><?= $page->title() ?></h1>
        <?php if ($page->intro()->isNotEmpty()): ?>
        <div class="intro-text text">
          <?= $page->intro()->kt() ?></p>
        </div>
        <?php endif ?>
      </header>

    <?php foreach ($categories as $category): ?>
      <section class="dishes">
        <h2><?= $category ?></h2>
        <?php foreach ($page->$category()->toStructure() as $links_title): ?>
        <article class="dish">
          <h3 class="dish-name"><?= $links_title->links_title() ?></h3>
          <p class="dish-description"><?= $links_title->links_description() ?></p>
          <p class="dish-price">€ <?= $links_title->links_url() ?></p>
          <p class="dish-price">€ <?= $links_title->url_lang() ?></p>

        </article>
        <?php endforeach ?>
      </section>
      <?php endforeach ?>


    </main>

    <?php snippet('footer') ?>

The reason why it doesn’t work is that your categories contain the labels of your field names, not the field names.

So in the foreach loop, what you should be calling is for example $page->links_carolefredericks()->toStructure() but what you are trying to do is call $page->Carole Frederics()->toStructure() (because that value is stored in $category when you loop through the categories. That cannot possibly work, because a) a method cannot have a space and b) that is not the field name.

Possible solution:

$categories = [
            'links_carolefredericks'  => 'Carole Fredericks',
            'links_musicwebsite'      => 'Music Websites',
            'links_tvshowwebsites'    => 'TV show Websites',
            'links_blogs'             => 'Blogs',
            'links_misc'              => 'Misc'
        ];

Then in template:

<?php foreach ($categories as $key => $category): ?>
      <section class="dishes">
        <h2><?= $category ?></h2>
        <?php foreach ($page->$key()->toStructure() as $links_title): ?>
        <article class="dish">
          <h3 class="dish-name"><?= $links_title->links_title() ?></h3>
          <p class="dish-description"><?= $links_title->links_description() ?></p>
          <p class="dish-price">€ <?= $links_title->links_url() ?></p>
          <p class="dish-price">€ <?= $links_title->url_lang() ?></p>

        </article>
        <?php endforeach ?>
      </section>
      <?php endforeach ?>

Thanks you. It helps me a lot :slight_smile:

You are welcome. Don’t hesitate to ask if anything is not clear yet.