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
}
}
6120
February 2, 2023, 10:07pm
3
Why not create another layout ?
Zuluru
February 2, 2023, 10:15pm
4
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.