rarst / meadow
WordPress 模板 DSL
0.3
2018-12-31 08:33 UTC
Requires
- php: >=7.0
- pimple/pimple: ^3.2.3
- twig/twig: ^2.6
Requires (Dev)
- pds/skeleton: ^1.0
This package is auto-updated.
Last update: 2024-08-29 04:42:49 UTC
README
使用熟悉的简便性和现代功能轻松编写 WordPress 主题模板。
Meadow 是一个主题模板解决方案,旨在在原生 WordPress 概念和 Twig 专用模板语言的力量之间找到平衡。
安装
使用 Composer 在您的主题项目中要求此包
composer require rarst/meadow
在主题加载期间某个时间实例化对象
$meadow = new \Rarst\Meadow\Core; $meadow->enable();
模板化
Meadow 遵循 WordPress 模板层次结构 的约定
- 例如
index.php
变为index.twig
。 {{ get_header() }}
将查找header.twig
(如果找不到,将回退到header.php
)- 等等。
模板标签
模板标签 API(以及一般 PHP 函数)被设置为从 Twig 模板透明地工作
{{ the_title() }}
过滤器
WordPress 过滤器被设置为作为 Twig 过滤器可用
{{ 'This is the title'|the_title }}
模板继承
Twig 功能的全系列自然可用,包括 模板继承
{# single.twig #} {% extends 'index.twig' %} {% block entry_title %} <div class="page-header">{{ parent() }}</div> {% endblock %}
要继承父模板,在子主题中在其前面加上文件夹的名称
{# child-theme/index.twig #} {% extends 'parent-theme/index.twig' %}
领域特定语言
Meadow 试图不仅“映射” WordPress 到 Twig,还通过实现自定义 Twig 标签、抽象特定任务复杂性来有意义地扩展两者,以改善历史上笨拙的 WP 结构。
这主要通过实现自定义 Twig 标签来实现,抽象特定任务的复杂性。
循环
{% loop %} <h2><a href="{{ the_permalink() }}">{{ the_title() }}</a></h2> {{ the_content() }} {% endloop %}
次要循环
{% loop { 'post_type' : 'book', 'orderby' : 'title' } %} {# expression for arguments #} <h2><a href="{{ the_permalink() }}">{{ the_title() }}</a></h2> {{ the_content() }} {% endloop %}
注释
<ul class="comment-list"> {% comments %} <li> {{ comment_text() }} {# no </li> - self-closing #} {% endcomments %} </ul>
模板示例
在 Hybrid Wing 主题(工作进行中)
许可
MIT