phug/component
最新稳定版本:1.1.4
Composer 安装命令:
composer require phug/component
包简介
Extension for pug-php and phug to use components in templates
关键字:
README 文档
README
Extension for Pug-php and Phug to use components in templates
Installation
composer require phug/component
Enable it globally:
\Phug\Component\ComponentExtension::enable();
To enable it automatically when calling static methods render, renderFile,
display, displayFile etc. on either \Pug\Facade or \Phug\Phug class.
If using in a \Pug\Pug or \Phug\Renderer instance, add the ComponentExtension
class to modules:
$pug = new \Pug\Pug([/*options*/]); \Phug\Component\ComponentExtension::enable($pug);
Usage
//- Register a component component alert .alert.alert-danger .alert-title slot title slot section //- Somewhere later in your template +alert slot title | Hello #[em world]! p This is an alert!
Output:
<section> <div class="alert alert-danger"> <div class="alert-title"> Hello <em>world</em>! </div> <p>This is an alert!</p> </div> </section>
Default slots
component page
header
slot header
| Default header
slot
footer
slot footer
| Default footer
+page
| My page content
slot footer
| Custom footer
Output:
<header> Default header </header> My page content <footer> Custom footer </footer>
Parameters
Component inherit mixin behavior.
Parameters can be passed as in mixins:
component page($title)
header
h1=$title
slot
footer
slot footer
| Footer of #{$title} page
+page("Contact")
| Contact us
($title becomes title if you use pug-php or js-phpize)
Output:
<header> <h1> Contact </h1> </header> Contact us <footer> Footer of Contact page </footer>
Fallback component
This package also include a function to get the first defined mixin/component among given names:
component page
| Page component
+#{$firstComponent('customPage', 'page')}
Output:
Page component
And if customPage component is defined, it will be used instead:
component page
| Page component
component customPage
| CustomPage component
+#{$firstComponent('customPage', 'page')}
Output:
CustomPage component
($firstComponent becomes firstComponent if you use pug-php or js-phpize)
$firstMixin is also available as an alias.
统计信息
- 总下载量: 35.51k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-01-15