Is this the best approach to show a sidebar depending

I’m trying to show a sidebar in other pages except, home page, and two other pages,
I’m asking, looking at the code below, am I go about it the recommended way or you have some suggestion for me. Thank you

//templates/layout/default.php
<?php if (!in_array($this->getRequest()->getParam('controller'), ['Pages', 'Users', 'Another page'])) echo $this->element('sidebar'); echo $this->fetch('user_sidebar'); ?>

$this->getRequest()->getParam('controller') gives you ONLY the name of the used controller, not the action nor other params.

So if you have 3 static pages which are all handled via the PagesController::display method you will need something like:

$request = $this->getRequest();
$currentController = $request->getParam('controller');
$currentAction = $request->getParam('action');
$pass = $request->getParam('pass');

if($currentController === 'Pages' && currentAction === 'display'){
    if ($pass === 'home') {
        // do something here
    } else if ($pass === 'other') {
        // do something else
    }
}

Why not create another layout ?

Or set a “no_sidebar” variable to true in those few exceptions, and show it only if that’s not set? There are many ways to attack this.