October CMS resources and help articles

Simple and to the point. Optimized by the community.

Search for CMS pages in alternate theme

1
by mjauvin, last modified on April 2nd, 2020

If you'd like to show pages in an alternate theme (other than the active theme), you can do so by adding this to your plugin's registration file's boot/register method:

Event::listen('cms.page.beforeDisplay', function ($controller, $url, $page) {
    if (!$page) {
        $altTheme = \Cms\Classes\Theme::load('myOtherTheme');
        $altController = new \Cms\Classes\Controller($altTheme);
        if ($page = $altController->getRouter()->findByUrl($url)) {
            return $page;
        }
    }
});

If a page with the requested URL is not found in the active theme, it will look for it in the alternate theme.

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?