getkirby / layouts
Kirby 布局
2.0.1
2023-05-09 16:53 UTC
Requires
- php: >=8.0.0 <8.3.0
- getkirby/cms: >=3.9.0
- getkirby/composer-installer: ^1.2.1
README
此插件扩展了 Kirby 的新片段,并从 site/layouts
加载布局片段
此版本的插件需要 Kirby 3.9.0,并帮助从旧布局插件迁移到我们新的片段。我们建议使用原生片段。
安装
下载
下载并将此存储库复制到 /site/plugins/layouts
。
Git 子模块
git submodule add https://github.com/getkirby/layouts.git site/plugins/layouts
Composer
composer require getkirby/layouts
工作原理
您可以在新的 /site/layouts
文件夹中创建完整的 HTML 布局。布局可以定义槽位,然后模板将填充内容。布局基于我们的新槽位片段,工作方式完全相同。唯一的不同是文件夹位置。您可以在我们的文档中了解更多关于我们的槽位片段的信息: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>
选择布局
要使用特定布局,您可以将布局名称传递给 layout()
方法。
/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 -->
使用槽位
您可以在布局中添加任意数量的不同槽位。默认槽位无需指定特定名称。其他每个槽位都需要一个唯一的名称。布局中的槽位可以定义默认内容,如果模板未使用该槽位,则会渲染此内容。
阅读更多:http://getkirby.com/docs/guide/templates/snippets#passing-slots-to-snippets
什么是 Kirby?
- getkirby.com – 了解 CMS。
- 试用 – 通过我们的在线演示进行测试。或者下载我们的套件开始。
- 文档 – 阅读官方指南、参考和食谱。
- 问题 – 报告错误和其他问题。
- 反馈 – 您有 Kirby 的想法?分享它。
- 论坛 – 遇到困难时,不要犹豫,寻求问题和支持。
- Discord – 闲逛并与社区见面。
- Mastodon – 传播信息。
- Instagram – 分享您的作品:#madewithkirby。
许可证
MIT