Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Yii2, how can I exclude layout from rendering in a view file?

Tags:

php

yii2

I have an admin login page that I want to render without the layout. How can I render a view in Yii2 without rendering the main layout?

like image 243
learner Avatar asked Mar 31 '15 06:03

learner


3 Answers

This can be done using renderPartial() method.

You can get more from the official documentation. Here's a link!

like image 141
Zack Avatar answered Oct 14 '22 03:10

Zack


In your controller you can assing layout for all actions of controller or turn it off:

class AdminController extends Controller
{
//  public $layout='//admin';
  public $layout=false;

OR you can do it for only one action:

public function actionIndex()
{
  $this->layout = false;
like image 29
user1852788 Avatar answered Oct 14 '22 03:10

user1852788


You can use renderPartial to exclude header and footer of layout from view file. However if you renderPartial it will not load asset files (css and js files). To load asset files without layout you can use renderAjax.

like image 41
Ninja Turtle Avatar answered Oct 14 '22 03:10

Ninja Turtle