This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Mavitm
How do I change the layout depending on the variables?
I've done a lot of experiments, I found the code below but it didn't work
Event::listen('cms.page.beforeDisplay', function ($controller, $url, $page) {
if (!$page || $url === '404') {
return $page;
}
// Assign the page's layout with your selected layout
if(config('detect.device') === 'mobile')
{
$page->layout = \Cms\Classes\Layout::loadCached(\Cms\Classes\Theme::getActiveTheme(), 'mobile.htm');
}
else
{
$page->layout = \Cms\Classes\Layout::loadCached(\Cms\Classes\Theme::getActiveTheme(), 'default.htm');
}
//$page->layout = \Cms\Classes\Layout::load(\Cms\Classes\Theme::getActiveTheme(), 'mobile.htm');
return $page;
});
I get an error like the bottom
Serialization of 'Closure' is not allowed
/var/www/lsport/vendor/october/rain/src/Halcyon/Builder.php line 725
Mavitm
solution of the problem
Event::listen('cms.page.beforeDisplay', function ($controller, $url, $page) {
if (!$page || $url === '404') {
return $page;
}
if(config('detect.device') === 'mobile')
{
$page->layout = 'mobile';
}
else
{
$page->layout = 'default';
}
return $page;
});
1-2 of 2