clthck / cakephp-pug
CakePHP 3 的 Pug 模板引擎插件
v1.0.1
2017-02-24 06:44 UTC
Requires
- php: >=5.5.30
- cakephp/cakephp: ~3.0
- erusev/parsedown: *
- talesoft/tale-pug: *
README
CakePHP 3 的 Pug 模板引擎插件
由 Tale Pug for PHP 提供。
安装
- 下载 Composer 或更新
composer self-update
。 - 运行
php composer.phar require clthck/cakephp-pug
。
如果Composer已全局安装,则运行
composer require clthck/cakephp-pug
引导
将以下内容添加到您的 config/bootstrap.php
以加载插件。
Plugin::load('PugView');
应用程序全局使用
将以下内容放置到您的 AppController.php
以加载 PugView 类。
public function initialize() { parent::initialize(); $this->viewBuilder() ->className('PugView.Pug') ->options(['pretty' => false]); }
如果我们需要为我们的 PugView 实例加载额外的助手类怎么办?在这种情况下,我们可以使 AppView 类继承 PugView 类
... use PugView\View\PugView; ... class AppView extends PugView { ... public function initialize() { $this->viewOptions([ 'pretty' => true ]); parent::initialize(); $this->loadHelper('Form', [ 'templates' => 'form_template' ]); } }
在模板文件 (.ctp.pug) 中
使用 $view
而不是 $this
。
= $view->Flash->render()
CakePHP JavaScript 块的使用示例
- $view->Html->scriptStart(['block' => true])
|
$(function() {
// Your js code goes here..
});
- $view->Html->scriptEnd()
如果您正在使用 Sublime Text 2/3,您需要安装 cakephp-jade-tmbundle 以正确启用语法高亮。
语言语法参考
请访问 jade.talesoft.codes 查看语法参考。