getkirby/layouts

Kirby Layouts

Fund package maintenance!
getkirby.com/buy

Installs: 8 285

Dependents: 0

Suggesters: 0

Security: 0

Stars: 42

Watchers: 8

Forks: 2

Open Issues: 0

Type:kirby-plugin

2.0.1 2023-05-09 16:53 UTC

This package is auto-updated.

Last update: 2024-12-09 20:19:01 UTC


README

This plugin extends Kirby’s new snippets with slots and loads layout snippets from site/layouts

This version of the plugin requires Kirby 3.9.0 and helps to migrate from the old layout plugin to our new snippets. We recommend to use native snippets instead.

Installation

Download

Download and copy this repository to /site/plugins/layouts.

Git submodule

git submodule add https://github.com/getkirby/layouts.git site/plugins/layouts

Composer

composer require getkirby/layouts

How it works

You can create full HTML layouts in a new /site/layouts folder. Layouts can define slots, which will then be filled with content by templates. Layouts are based on our new snippets with slots and work exactly the same way. The only difference is the folder location. You can learn more about our snippets with slots in our docs: http://getkirby.com/docs/guide/templates/snippets#passing-slots-to-snippets

/site/layouts/default.php

<html>
  <head>
    <title><?= $page->title() ?></title>
  </head>
  <body>
    <?= $slot ?>
  </body>
</html>

/site/templates/my-template.php

<?php layout() ?>

<h1>Hello world</h1>
<p>This will end up in the default slot</p>

Choosing a layout

To use a specific layout, you can pass its name to the layout() method.

/site/layouts/blog.php

<html>
  <head>
    <title>Blog</title>
  </head>
  <body>
    <h1>Blog</h1>
    <?= $slot ?>
  </body>
</html>

/site/templates/blog.php

<?php layout('blog') ?>

<!-- some articles -->

Working with slots

You can add as many different slots to your layout as you need. The default slot goes without a specific name. Every other slot needs a unique name. Slots in layouts can define default content, which will be rendered if the slot is not used in the template.

Read more: http://getkirby.com/docs/guide/templates/snippets#passing-slots-to-snippets

What’s Kirby?

  • getkirby.com – Get to know the CMS.
  • Try it – Take a test ride with our online demo. Or download one of our kits to get started.
  • Documentation – Read the official guide, reference and cookbook recipes.
  • Issues – Report bugs and other problems.
  • Feedback – You have an idea for Kirby? Share it.
  • Forum – Whenever you get stuck, don't hesitate to reach out for questions and support.
  • Discord – Hang out and meet the community.
  • Mastodon – Spread the word.
  • Instagram – Share your creations: #madewithkirby.

License

MIT

Credits