0

How can I get the current page layout programatically?

I have tried this:

$block->getLayout()->getUpdate()->getPageLayout();

But the output is: 1column but that is wrong.

Any idea how to get it?

3

1 Answer 1

0

Add this code in your file where you want to get.

protected $request;

public function __construct(
    ............................................
    \Magento\Framework\App\Request\Http $request,
    ............................................
){
    ............................................
    $this->request = $request;
    ............................................
}

Now you can add this code in your custom function or execute() function

    $controller = $this->request->getControllerName();
    $action     = $this->request->getActionName();
    $route      = $this->request->getRouteName();

    echo $controller."<br/>";
    echo $action."<br/>";
    echo $route."<br/>";

I Hope This Helps You.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.