【问题标题】:Same Layout - Unique Class Names with October CMS相同的布局 - 十月 CMS 的唯一类名
【发布时间】:2016-08-09 14:25:14
【问题描述】:

我是十月 CMS 的新手,想知道如何在使用相同布局时在不同页面上创建唯一的类名。例如,主页可能是<html class="home">,而博客页面可能是<html class="blog">等等。

关于如何做到这一点的任何建议?

谢谢

【问题讨论】:

    标签: octobercms


    【解决方案1】:
    <body class="page-{{ this.page.id }} layout-{{ this.layout.id }}">
    

    您可以通过this.page 访问当前页面对象,它返回对象Cms\Classes\Page。这个对象也可以在 PHP 代码中访问。 this.page 具有以下属性:布局、id、标题等。更多信息您可以找到here

    【讨论】:

    • 谢谢;但需要对其进行编辑(使用edit 按钮)。我已经为你做了。
    【解决方案2】:

    简单的方法 - 创建部分并包含在页面中:

    pages/home.htm

    title = "home"
    url = "/home"
    layout = "mylayout"
    ==
    <?php
        function onStart() 
        {
            $this['class'] = 'home';
        }
    ?>
    ==
    {% partial mypage.htm %}
    

    pages/blog.htm

    title = "blog"
    url = "/blog"
    layout = "mylayout"
    ==
    <?php
        function onStart() 
        {
            $this['class'] = 'blog';
        }
    ?>
    ==
    {% partial mypage.htm %}
    

    在 partials/mypage.htm

    <html class="{{ class }}">
    

    【讨论】:

      猜你喜欢
      • 2017-05-22
      • 2016-05-18
      • 2017-08-06
      • 2015-06-07
      • 1970-01-01
      • 2021-11-10
      • 1970-01-01
      • 2018-04-22
      • 1970-01-01
      相关资源
      最近更新 更多