gglnx / twig-component-handle-loader
使用Fractal-style组件句柄加载Twig模板
2.0.1
2022-06-09 11:00 UTC
Requires
- php: >=7.2.5
- twig/twig: ^3.0
Requires (Dev)
README
基于Twig的加载器,通过基于Fractal命名约定的组件句柄加载模板。
例如
├── components
│ └── small-components
| └── button
| └── button.twig # Will be @button
现在您可以使用@[component-handle]
语法包含按钮模板
{% include '@button' %}
需求
- Twig >=2.14
- PHP >=7.4
安装
推荐通过Composer安装此加载器
composer require gglnx/twig-component-handle-loader
然后您可以直接使用此加载器与Twig一起使用
require_once '/path/to/vendor/autoload.php'; $loader = new \Gglnx\TwigComponentHandleLoader\Loader\ComponentHandleLoader('../path-to-my-components'); $twig = new \Twig\Environment($loader);
您还可以使用ChainLoader
将此加载器与其他加载器结合使用。
此加载器与Fractal实现之间的差异
需要读取相应的组件配置以添加前缀和重写组件句柄。这可能超出了此加载器的范围,也许更适合放在特定的Twig Fractal加载器中。