18

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?

learner
  • 391
  • 1
  • 2
  • 11

3 Answers3

33

This can be done using renderPartial() method.

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

Zack
  • 1,527
  • 2
  • 20
  • 32
18

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;
user1852788
  • 4,278
  • 26
  • 25
  • 1
    This worked for me, in my case I wanted to keep the Assets to let jquery works on view so I created a new layout file without logo and headers and assing it as your example `public function actionIndex() { $this->layout = 'mynewlayout';` – Ezequiel Alanis Feb 10 '19 at 15:46
1

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.

Ninja Turtle
  • 1,293
  • 2
  • 24
  • 50