R
R
rhost2014-09-30 07:24:46
Yii
rhost, 2014-09-30 07:24:46

How to install twig on yii2?

I did everything as described www.yiiframework.com/doc-2.0/guide-tutorial-templa...
I put yii2-app-basic
in web.php

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

created layout template - layout_main.twig (views/layouts/layout_main.twig)
created view - index.twig (views/site/index.twig)
in controller
public function actionIndex(){
        return $this->render('index.twig');
}

gives the error The view file does not exist: .....\views\layouts\main.php
What could be the problem?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
andreyqin, 2014-09-30
@andreyqin

Maybe you need to rename the main template to main.php?

K
Kron0S, 2015-10-30
@Kron0S

It is necessary to disable the default layout of the application

$config = [
  'layout' => false,
]

or only for the controller
class BaseController extends Controller
{
    public $layout = false;
}

D
Dima, 2015-12-23
@mikaspell

right, it will not work, because you did not specify through which layout to process your view.
It is necessary to specify a new layout in the controller, for example:

class SiteController extends Controller
{
    public $layout = 'layout_main.twig';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question