Giter Site home page Giter Site logo

layouts's Introduction

Kirby Layouts plugin

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

layouts's People

Contributors

afbora avatar bastianallgeier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

8grad modufolio

layouts's Issues

Layout extending Layout

Hello there,
would it be possible for a layout to extend a layout? Eg layout blog calls layouts/default.php via layout()?

Thanks!

Cannot install on PHP 8.2 with composer

Hi there,

This issue was reported in #9 and marked as fixed, but the fix was never published to Packagist, so in practice it's still not possible to composer require getkirby/layouts with PHP 8.2.

Breaks pages cache

If i use layouts and slots the pages cache is no longer created.

If i return a string here instead of Tpl::load it works and cache files are created.
Layout Class

static public function render(array $data = []): string
    {
        Slots::render();
        return Tpl::load(kirby()->root('site') . '/layouts/' . static::$name . '.php', array_merge(Layout::$data ?? [], $data));
    }
'cache' => [
    'pages' => [
      'active' => true
    ]
  ]

$page->isCacheable() returns true.
kirby()->cache('pages')->set('a.html', 'test'); creates a file so not a permission error.

osx valet, kirby 3.6.6

Nesting `slot()`s

Hey there,
I would like to nest slots - take the following scenario:

<?php slot('content') ?>
<section class="container">
    <?php slot() ?>
    some default content
    <?php endslot() ?>
</section>
<?php endslot() ?>

Most of the time, my templates would use slot(), drop some content, maybe echo $page->myfield()->toBlocks() etc but some templates would need to remove the container element and do something completely different. IMHO nesting slots would make this way more DRY, wouldn't it?

Thanks for considering this and have a good day,
S1SYPHOS

Global layout data not working

I tried to pass some data to the layout method, but I get "Undefined variable" error every time.

My template:
/site/templates/default.php

<?php layout("default", ["title" => "Some title"]) ?>

<p>Some content...</p>

Layout:
/site/layouts/default.php

<?= $title ?>

<?php slot() ?>
<?php endslot() ?>

Latest version of Kirby Plainkit, no other plugins installed.

Minimum required PHP version

I think the PHP requirement in the composer.json might be wrong.
Right now I can't install this plugin on PHP 8.2.3 as it has to be below 8.2.0.
Using >=8.0.0 <8.3.0 should probably fix that.

Breaks `$page->render()`

I've been preparing an error issue for the Kirby Static Site Generator not working if layouts are used, but looking closely at the problem, it seems there's something weird happening with the render() function when the layouts plugin is used.

If I call $page('error')->render() with the layouts plugin on, the $page refers to the error (correct) page in the layout, but refers to the last rendered / first requested page (see edit) in the template itself.

You can see the problem in the kirby/ssg/layouts demo repo build files:

result of page('error')->render():

<!DOCTYPE html>
<html class="no-js">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width">

	<title>Error • Site Title</title>
	<script type="module">
		document.documentElement.classList.remove('no-js');
		document.documentElement.classList.add('js');
	</script>

	<link rel="icon" href="/favicon.png">
	<link rel="icon" href="/favicon.svg" type="image/svg+xml">
</head>

<body class="antialiased dark:bg-gray-900 dark:text-white">

<h1>Home</h1>

</body>
</html>

Edit:

Order matters. templates get whatever page called 'render' first.

// generates `<h1>Error</h1>` in the template body
page('error')->render();

// generates `<h1>Home</h1>` in the template body of both
page('home')->render(); page('error')->render();

// generates `<h1>Error</h1>` in the template body of both
page('error')->render(); page('home')->render();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.