简体   繁体   中英

October CMS - Conditionally Load a Different Page

I'm in the process of building a site in October CMS that uses a slash page. The splash page is only supposed to show to non cookied users the first time that they visit the site. I am controlling this part via a component in a plugin called splash. Here is my onRun() function:

public function onRun()
{
    $key = 'shownsplash';
    if(!Session::has($key) || !Cookie::get($key))
    {
        $this->page['showsplash'] = true;
        Cookie::queue('shownsplash',true);
        Session::put($key,true);
        $resp = NULL;
    }
}

In my main page layout called 'default' I want to conditionally load the splash page template called 'splash' using the following:

{% if showsplash %}
     {{ loadpage('splash') }}
{% else %}
     Regular page template
{% endif %}

Except that I'm not sure how to load a page conditionally. One additional requirement is that the splash page takes the url http://www.example.com and not any subsequent pages. Can anyone point out how to do this?

in octobercms cms/page are hit by url , the url set in the config section and are bound to a layout. so for me page are more 'routing' object than html content holder.

In fact partials ARE html content holder

So if i had to do the same thing as you mean i would use partial and page. a page with url="/" and two partials, one for the regular page and one for the splash. bind your plugin component to the page not the layout

{% if showsplash %}
    {% partial 'home/splash.htm' %}
{% else %}
    {% partial 'home/regular.html' %}
{% endif %}

I think partial are exactly what to use in this kind of conditional stuff. generaly think of

  • layout as website structuration
  • page mainly for routing
  • partial for html content

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM