Pug Yii2 adapter

Related tags

Frameworks pug-yii2
Overview

Yii 2 Pug (ex Jade) extension

This extension provides a view renderer for Pug templates for Yii framework 2.0 applications.

License Latest Stable Version Travis CI Build Status Test Coverage Issue Count StyleCI

Support

Installation

The preferred way to install this extension is through composer.

Either run

composer require pug/yii2

or add

"pug/yii2": "^1.0",

to the require section of your composer.json file.

Configure



return [
  // ...
  'components' => [
    // ...
    'view' => [
      // ...
      'renderers' => [
        'pug' => 'Pug\\Yii\\ViewRenderer',
      ],
    ],
  ],
];

You can also use other pug renderer like phug or tale-pug



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 then replace 'Tale\\Pug\\Renderer' with 'Tale\\Pug\\Renderer' 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 cachePath and/or 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: app (Yii::$app) and view (view 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:

h1=_yii.view.defaultExtension
p=_yii.app.version

Or if you set the expressionLanguage option to "php":

h1=$_yii->view->defaultExtension
p=$_yii->app->getVersion()

Credits

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.

You might also like...
Yii2 console application used to write our processors of methods to responsible to client calling.

Microservice Application Skeleton Yii2 console application used to write our processors of methods to responsible to client calling. This application

Date/Time Picker widget for Yii2 framework Based on Eonasdan's Bootstrap 3 Date/Time Picker
Date/Time Picker widget for Yii2 framework Based on Eonasdan's Bootstrap 3 Date/Time Picker

Yii2 Date/Time Picker Widget Date/Time Picker widget for Yii2 framework Based on Eonasdan's Bootstrap 3 Date/Time Picker Demo Since this is a part of

Yii2 extension for format inputs based on AutoNumeric.js

Yii2 extension for format inputs based on AutoNumeric.js

Yii2 SwitchInput widget turns checkboxes and radio buttons into toggle switchinputes

Yii2 SwitchInput widget turns checkboxes and radio buttons into toggle switchinputes

An enhanced FileInput widget for Bootstrap 4.x/3.x with file preview, multiple selection, and more features (sub repo split from yii2-widgets)
An enhanced FileInput widget for Bootstrap 4.x/3.x with file preview, multiple selection, and more features (sub repo split from yii2-widgets)

yii2-widget-fileinput The FileInput widget is a customized file input widget based on Krajee's Bootstrap FileInput JQuery Plugin. The widget enhances

An enhanced Yii 2 widget encapsulating the HTML 5 range input (sub repo split from yii2-widgets)
An enhanced Yii 2 widget encapsulating the HTML 5 range input (sub repo split from yii2-widgets)

yii2-widget-rangeinput The RangeInput widget is a customized range slider control widget based on HTML5 range input. The widget enhances the default H

A Yii2 module for embedding social plugins and widgets.
A Yii2 module for embedding social plugins and widgets.

yii2-social Module that enables access to social plugins for Yii Framework 2.0. It includes support for embedding plugins from the following networks

This is Yii2 utilities

YII2-UTILITY This is Yii2 utilities. Requirements PHP = 7.4 Curl extension for PHP7 must be enabled. Download Using Composer From your project direct

Alejandro Flores, Php Yii2 Emoac

Prueba Tecnica Emoac Proyecto basado en PHP con Yii2. Hecho por Alejandro Flores, Ingeniero en informática. Este proyecto consta de un CRUD de product

Releases(1.2.0)
Owner
Pug PHP
Pug PHP
An extended bootstrap alert and alert block widget for Yii2 (sub repo split from yii2-widgets)

yii2-widget-alert This extension contains a couple of useful widgets. The Alert widget extends the \yii\bootstrap\Alert widget with more easy styling

Kartik Visweswaran 28 Mar 12, 2022
Simple RBAC Manager for Yii2 (minify of yii2-admin)

Yii2 Mimin Simple RBAC Manager fo Yii 2.0. Minify of yii2-admin extension with awesome features Attention Before you install and use this extension, t

Hafid Mukhlasin 52 Sep 22, 2022
This extension provides a view renderer for Pug templates for Yii framework 2.0 applications.

This extension provides a view renderer for Pug templates for Yii framework 2.0 applications.

Revin Roman 9 Jun 17, 2022
PSR-15 Adapter for InertiaJS

inertia-psr15 Before using this library, is important to know what is Inertia.js, what is it for and how it works, in the official Inertia.js website

Mohamed Cherif Bouchelaghem 28 Oct 26, 2022
LaravelS is an out-of-the-box adapter between Swoole and Laravel/Lumen.

?? LaravelS is an out-of-the-box adapter between Swoole and Laravel/Lumen.

Biao Xie 3.7k Dec 29, 2022
Tarantool connector for yii2 framework. Allow to use activerecord, schemas, widgets and more.

Tarantool connector for yii2 framework Tarantool connector for yii2 framework. Allow to use framework abstractions such as ActiveRecord, Schema, Table

Andrey 11 Nov 21, 2021
Web Push Notifications brought to Yii2

Web Push Notifications for Yii 2 An extension for implementing Web Push Notifications on your website in a breeze. Documentation is at docs/README.md

Mehdi Achour 12 May 19, 2022
yii2-app-advanced with Twitter Bootstrap 5

Yii 2 Advanced Project Template is a skeleton Yii 2 application best for developing complex Web applications with multiple tiers.

Nedarta 1 Nov 5, 2021
Prometheus exporter for Yii2

yii2-prometheus Prometheus Extension for Yii 2 This extension provides a Prometheus exporter component for Yii framework 2.0 applications. This extens

Mehdi Achour 3 Oct 27, 2021
Yii2-symfonymailer - Yii 2 Symfony mailer extension.

Yii Mailer Library - Symfony Mailer Extension This extension provides a Symfony Mailer mail solution for Yii framework 2.0. For license information ch

Yii Software 28 Dec 22, 2022