Layouts play a major role in Magento to override existing core files without affecting a system. Magento supports various types of layouts like 1 column, 2 column-left, 2 column-right, 3 columns, etc. The structure of all pages is described in the layout file. Technically, a layout is an .xml file which contains declarations and different instructions. When it comes to building a page inside your store to give a touch of the personalized store environment, you need to change your layout file at the end. But What if you acquire dynamic layout programmatically?

Today, I’m again back with a small piece of code that will help you to easily override page layout programmatically in Magento 2. You can even set page layout of the controller action which resides on similar location like this.
Go to app/code/Vendor/Extension/Controller/Youraction/Action.php ans paste below code here.

Click to rate this post!
[Total: 7 Average: 3.1]