Creating a custom view renderer
There are many PHP template engines out there. Yii2 only offers native PHP templates. If you want to use one of the existing template engines or create your own one, you have to implement it—of course, if it's not yet implemented by the Yii community.
In this recipe we'll re-implement the Smarty templates support.
Getting ready
- Create a new
yii2-app-basic
application using the composer, as described in the official guide at http://www.yiiframework.com/doc-2.0/guide-start-installation.html. - Install the Smarty library:
composer require smarty/smarty
How to do it…
Carry out the following steps for creating a custom view renderer:
- Create the
smarty/ViewRenderer.php
file:<?php namespace app\smarty; use Smarty; use Yii; class ...
Get Yii2 Application Development Cookbook - Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.