Today we talk about how in Magento 2 set layout controller. You can set any layout in your controller file. In this example we are setting 3columns layout in our controller. You can set any layout your own controller. There is list of available layout in magento 2.
Available Layout
List of layout you can set in your controller.
1column
2columns-left
2columns-right
3columns
empty
Set Template in controller
Magento 2 using setPageLayout to setting the layout of current page.
public function execute()
{
$page = $this->resultPageFactory->create(false, ['isIsolated' => true]);
$customLayout = '3columns';
$page->getConfig()->setPageLayout($customLayout);
return $page;
}
{
$page = $this->resultPageFactory->create(false, ['isIsolated' => true]);
$customLayout = '3columns';
$page->getConfig()->setPageLayout($customLayout);
return $page;
}