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

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.


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;

This can be done using renderPartial() method.

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

Tags:

Php

Yii2