getkirby / layouts Goto Github PK
View Code? Open in Web Editor NEWExtend Kirby’s templates with a powerful layout system
License: MIT License
Extend Kirby’s templates with a powerful layout system
License: MIT License
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.
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();
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
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.
Hello there,
would it be possible for a layout to extend a layout? Eg layout blog
calls layouts/default.php
via layout()
?
Thanks!
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.
Would love to have the ability to register layouts via a plugin instead of having to have inside of the site/layouts
folder.
'layouts' => [
'default' => __DIR__ . '/layouts/default.php',
'blog' => __DIR__ . '/layouts/blog.php',
…
],
Related forum post: https://forum.getkirby.com/t/how-do-i-register-layouts-in-plugins/25455
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.