Yii 2 Pug (ex Jade) extension
The preferred way to install this extension is through composer.
composer require pug/yii2
require section of your
<?php return [ // ... 'components' => [ // ... 'view' => [ // ... 'renderers' => [ 'pug' => 'Pug\\Yii\\ViewRenderer', ], ], ], ];
<?php return [ // ... 'components' => [ // ... 'view' => [ // ... 'renderers' => [ 'pug' => [ 'class' => 'Pug\\Yii\\ViewRenderer', 'renderer' => 'Phug\\Renderer', ], ], ], ], ];
Phug and Pug-php (the default renderer) are automatically installed
when you install the last version of
pug/yii2, for other pug renderer,
replace the renderer class and include it.
For example, for Tale-pug, use
composer require talesoft/tale-pug
in the config example above.
Cache path and View path
By default, this extension uses
'@runtime/pug/cache' to store compiled
templates, and looks in
'@app/views' to find the templates to compile.
You can change this, by specifying
viewPath in the
configuration, for example:
return [ // ... 'components' => [ // ... 'view' => [ // ... 'renderers' => [ 'pug' => [ 'class' => 'Pug\\Yii\\ViewRenderer', 'cachePath' => '@app/runtime/Pugcache', 'viewPath' => '@app/themes/dark/templates/views', ], ], ], ], ];
pug/yii provide 2 global variables:
path given to
->render() in your controller). It imply that:
- If you set app or view shared variables, they will be erased by those system values.
- If you pass app or view locals to the
->render()method they will have the precedence on system values.
To avoid such name conflict, you can pack into on object and store in a shared variable with a name you chose:
return [ // ... 'components' => [ // ... 'view' => [ // ... 'renderers' => [ 'pug' => [ 'class' => 'Pug\\Yii\\ViewRenderer', // ... 'systemVariable' => '_yii', ], ], ], ], ];
With this config, app and view are no longer reserved names (can be used for your own locals or shared variables), only _yii is, and so you can get app and view like this:
Or if you set the
expressionLanguage option to
This solution merge both project rmrevin/yii2-pug (original fork that support pug-php 2) and jacmoe/yii2-tale-pug (tale-pug and tale-jade Yii2 solution) and finally bring support for pug-php 3 and phug engines.