Sergey P. aka azure
Sergey P. aka azure

Reputation: 4742

How to use Twig template engine with Yii2 framework?

I followed the instructions on yii2 documentation about using twig template engine

in config/web.php (which is included from index.php) I have:

'view' => [
            'class' => 'yii\web\View',
            'renderers' => [
                'twig' => [
                    'class' => 'yii\twig\ViewRenderer',
                    'cachePath' => '@runtime/Twig/cache',
                    'options' => ['auto_reload' => true], /*  Array of twig options */
                    'globals' => ['html' => '\yii\helpers\Html'],
                ],
            ],
        ],

in SiteController.php:

public function actionIndex()
    {
        echo $this->render('index.twig');
    }

in views/site/index.twig I have some text:

But instead of seeing raw html I see template based on views/layouts/main.php with index.twig content used as variable in main layout.

Upvotes: 3

Views: 3020

Answers (1)

Sergey P. aka azure
Sergey P. aka azure

Reputation: 4742

It was required to set layout to false in order to skip layout processing during redner

class BaseController extends Controller
{
    public $layout = false;
}

Upvotes: 2

Related Questions