Skip to content

Kirby 4.5.0

Restaurant menu

Easily list all those bites

Page blueprint

/site/blueprints/pages/menu.yml
title: Restaurant Menu
icon: 🍕

fields:
  starters:
    extends: fields/dishes
    label: Starters

  pasta:
    extends: fields/dishes
    label: Pasta

  meat:
    extends: fields/dishes
    label: Meat

  desert:
    extends: fields/dishes
    label: Desert

Reusable dishes field

/site/blueprints/fields/dishes.yml
label: Dishes
type: structure
fields:
  dish:
    label: Dish
    type: text
    width: 1/3
  description:
    label: Description
    type: text
    width: 1/3
  price:
    label: Price
    type: number
    before: €
    step: 0.01
    width: 1/3

Result

Example controller and template

Controller

site/controllers/menu.php
<?php
return function () {
    $categories = [
        'Starters',
        'Pasta',
        'Meat',
        'Desert'
    ];
    return [
        'categories' => $categories
    ];
};

Template

site/templates/menu.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 $dish): ?>
    <article class="dish">
      <h3 class="dish-name"><?= $dish->dish() ?></h3>
      <p class="dish-description"><?= $dish->description() ?></p>
      <p class="dish-price">€ <?= $dish->price() ?></p>
    </article>
    <?php endforeach ?>
  </section>
  <?php endforeach ?>

</main>

<?php snippet('footer') ?>