Changing $objPage->layout in your function is probably not enough in order to change the used layout. Look at the contao file /system/modules/core/pages/PageRegular.php:
Code: Alles auswählen
// Get the page layout
$objLayout = $this->getPageLayout($objPage);
// HOOK: modify the page or layout object (see #4736)
if (isset($GLOBALS['TL_HOOKS']['getPageLayout']) && is_array($GLOBALS['TL_HOOKS']['getPageLayout']))
{
foreach ($GLOBALS['TL_HOOKS']['getPageLayout'] as $callback)
{
$this->import($callback[0]);
$this->$callback[0]->$callback[1]($objPage, $objLayout, $this);
}
}
Right before the hook calls your function, $objLayout is created using $objPage. Changing $objPage in your function won't change anything unless you recreate $objLayout and override the existing $objLayout. We haven't tried it yet but we think, this might work:
Code: Alles auswählen
class ZzzProduct {
public function mygetPageLayout(\PageModel $objPage, \LayoutModel &$objLayout, \PageRegular $objPageRegular)
{
$product = \Input::get('product');
if(!empty($product)) {
$objPage->layout = 10; //10 is my new layout id
$objLayout = $this->getPageLayout($objPage);
}
}
The important thing is the function taking the $objLayout parameter as a reference using the & sign (so that we can manipulate it) and then overriding $objLayout with a newly created $objLayout that is based on the modifed $objPage.
Please let us know if it works.