如何在Yii2中使用自定义布局?

I want to use 3 templates for yii. I have files like these:

./views/layouts/main-template-1.php
./views/layouts/main-template-2.php
./views/layouts/main-template-3.php

What may I do to apply all of the layouts? Because I use 3 templates for my web. Thanks in advance

Simply place in the controller or controller's action

$this->layout = 'main-template-1'; // or 2 or 3

If you want to use layout for all actions in Controller ,

class SiteController extends Controller
{
    public $layout="main-template-1";
     // actions
}

If you want to use layout for specific action than use

public function actionIndex()
{
$this->layout = "main-template-1"; 
}

If you have basic template that you want to use you can set that in config/web.php like

'view' => [
        'theme' => [
            'pathMap' => [
                    '@app/views' =>[
                            '@app/themes/mytheme',
                            '@app/themes/yourtheme'
                            ]
                        ],
            'baseUrl' => '@web/../themes/mytheme',
        ],
    ],

this will take the layout of

app/themes/mytheme/layout/main.php

then in functions you could use other templates like

public function actionIndex()
{
   $this->layout = "main-template-1"; 
}