Change layout from view

Dear,

How can i change the layout from the view file, in Yii 1.x the following variable did the trick;

$this->layout = ‘newLayout’;

But in Yii2 this doesn’t work. I know I can set this from the controller action, but i am using static pages that are using the same render action, so i need to do this on view level.

Thanks.

Hi, try




$this->context->layout = 'newLayout';



Thanks! That worked!

This work in the controller action in Yii2

My actionLogin :

public function actionLogin()


{


    $this->layout = 'login'; // This change de layout use in actionLogin only...


    ...


    ...


    ...


 }