Winter CMS resources and help articles

Simple and to the point. Optimized by the community.

Make a simple page switcher

by DamsFX, last modified on September 12th, 2023

This page, if duplicated across themes, allows you to cycle between them. It is possible to limit the themes available for this loop (see comment note).

title = "Theme switch"
url = "/switch-theme"
layout = "default"
is_hidden = 0
    function onStart()
        use Cms\Classes\Theme;
        use Redirect;

        $themes = collect(array_pluck(Theme::all(), 'dirName'));
         * Use the above syntax to limit the availaibles themes
         * to those specified
        $themes = collect([

        $currentThemeKey = $themes->search(Theme::getActiveThemeCode());

        $nextThemeKey = $currentThemeKey +1;
        if ($nextThemeKey > $themes->count() -1) {
            $nextThemeKey = 0;

        $nextTheme = $themes->only($nextThemeKey)->first();

        return Redirect::to('/');

If only two themes are defined, the page behaves like a "theme switcher".



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