How to get the layout name in the controller?

Hello,
in AppController.php I have:

    public function beforeFilter(EventInterface $event)
{
    parent::beforeFilter($event);
    $this->viewBuilder()->setLayout('default_admin');
}

How do I get the layout name in the controller or in the component?

Thank You…

The ViewBuilder class has a public getLayout() method so from a controller you should be able to

$this->viewBuilder()->getLayout();

In a Component you would need to

$this->getController()->viewBuilder()->getLayout();

Here are more useful details of the ViewBuilder class

it returns null. :expressionless:

I can confirm in my code that if I have not explicitly set it, it will report null.

In the null case, I assume in that case the layout will eventually be set to ‘default’.