Magento 2 set layout controller

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;
}

Qaisar Satti

Hi, I'm Qaisar Satti! I've been a developer for over 20 years, and now I love sharing what I've learned through tutorials and guides. Whether you're working with Magento, PrestaShop, or WooCommerce, my goal is to make your development journey a bit easier and more fun. When I'm not coding or writing, you can find me exploring new tech trends and hanging out with the amazing developer community. Thanks for stopping by, and happy coding!

Leave a Reply