1

我正在十月 CMS 中构建一个使用斜线页面的网站。启动页面仅应在非 cookie 用户第一次访问该站点时显示给他们。我通过一个名为 splash 的插件中的组件来控制这部分。这是我的 onRun() 函数:

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;
    }
}

在我的名为“默认”的主页布局中,我想使用以下内容有条件地加载名为“splash”的启动页面模板:

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

除了我不确定如何有条件地加载页面。另一个要求是启动页面采用 url http://www.example.com而不是任何后续页面。谁能指出如何做到这一点?

4

1 回答 1

3

在 octobercms cms/page 中,被 url 击中,该 url 在配置部分中设置并绑定到布局。所以对我来说,页面比 html 内容持有者更“路由”对象。

事实上,partials 是 html 内容持有者

因此,如果我必须按照您的意思做同样的事情,我会使用部分和页面。一个带有 url="/" 的页面和两个部分,一个用于常规页面,一个用于启动页面。将您的插件组件绑定到页面而不是布局

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

我认为 partial 正是在这种有条件的东西中使用的。一般认为

  • 布局作为网站结构
  • 页面主要用于路由
  • 部分用于 html 内容
于 2016-03-04T14:10:02.963 回答