clthck/cakephp-pug

CakePHP 3 的 Pug 模板引擎插件

安装: 22

依赖者: 0

建议者: 0

安全: 0

星星: 6

关注者: 2

分支: 1

类型:cakephp-plugin

v1.0.1 2017-02-24 06:44 UTC

This package is not auto-updated.

Last update: 2024-09-14 20:04:18 UTC


README

Build Status Latest Stable Version Total Downloads License

CakePHP 3 的 Pug 模板引擎插件

Tale Pug for PHP 提供。

安装

  1. 下载 Composer 或更新 composer self-update
  2. 运行 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 查看语法参考。