美文网首页october cms
october cms页面介绍一

october cms页面介绍一

作者: ben2012 | 来源:发表于2017-09-19 00:45 被阅读0次

    说明


    所有网站都有页面。在october cms 页面用页面模板表示,页面模板文件存储在主题根目录下的pages目录下。根据页面功能进行相应的命名。文件扩展名为.htm。在页面中含有配置信息和twig模板引擎代码区。也可以含有php代码区域。

    title = "分类"
    url = "/categories/:slug"
    layout = "default"
    description = "分类列表页面"
    is_hidden = 0
    
    [blogCategories]
    slug = "{{ :slug }}"
    displayEmpty = 0
    categoryPage = "blog/category"
    ==
    <?php
    use RainLab\Blog\Models\Category;
    
    function onStart()
    {
        $slug = $this->param('slug');
        $slug = strchr($slug,'.',true);
        $this['category'] = Category::where('slug',$slug)->first();
    }
    
    
    function onEnd()
    {
        $this->page->title = $this['category']['name'];
    }
    ?>
    ==
    

    页面配置


    页面配置在页面的配置区内中定义,页面配置定义了页面参数,用于路由和页面组件所需要的页面参数

    参数 描述
    url 页面路由、必填、url格式语法下面有描述
    title 标题、必填
    layout 页面布局、可选 应包含布局文件的名称,不包括扩展名,如:default
    description 后端界面的页面说明描述、可选

    配置语法


    页面路由地址由url配置参数定义。url应以/开头,并且可以包含参数。没有参数的url是有固定的格式。在以下示例中,页面URL是/blog。

    1. 不含参数的url
    url = "/blog"
    

    具有参数的url更灵活。以下示例中定义的URL模式的页面将匹配如下来url地址的路由/categories/:slug。url参数中的:slug可通过组件或php代码区进行处理,比如我这个blog分类。

    /categories/:slug
    

    使用组件:编辑某page layout partials,选择组件,点击组件。会把组件自动挂载页面、布局、和部分上。


    组件
    [blogCategories]
    slug = "{{ :slug }}"
    displayEmpty = 0
    categoryPage = "blog/category"
    

    或使用代码选区

    use RainLab\Blog\Models\Category;
    
    function onStart()
    {
        $slug = $this->param('slug');
        $slug = strchr($slug,'.',true);
        $this['category'] = Category::where('slug',$slug)->first();
    }
    

    这样在页面模板中就可以直接使用category变量了。

    <section class="archives-wrap">
        <div class="archive-year-wrap">
          <a href="/archives/2017" class="archive-year">2017</a>
        </div>
        <div class="archives">
            {% for post in category.posts %}
            <article class="archive-article archive-type-post">
              <div class="archive-article-inner">
                <header class="archive-article-header">
                  <a href="/show/{{post.created_at|date('Ymd')}}/{{post.slug}}.html" class="archive-article-date">
                  <time datetime="{{post.created_at}}" itemprop="datePublished">{{post.published_at|date('m月d日')}}</time>
                 </a>      
                <h1 itemprop="name">
                  <a class="archive-article-title" href="/show/{{post.created_at|date('Ymd')}}/{{post.slug}}.html">{{post.title}}</a>
                </h1>
                </header>
              </div>
            </article>
            {% endfor %}
       </div>
    </section>
    

    如果参数可选择:post_id加上?

    url = "/blog/post/:post_id?"
    

    中间参数不能使用可选项、<font color="red">最好不要使用下面的路由</font>

    url = "/blog/:post_id?/comments"
    

    可选参数可以具有默认值,这些值用作回退值,以防在URL中未显示实际参数值。默认值不能包含任何星号,管道符号或问号。默认值在问号后面指定。在下一个示例中,该category_id参数将是10URL /blog/category。

    url = "/blog/category/:category_id?10"
    

    您还可以使用正则表达式来验证参数。要添加验证表达式,请在参数名称(或问号)后添加管道符号并指定表达式。表达式中不允许使用正斜杠符号。例子:

    url = "/blog/:post_id|^[0-9]+$/comments" - 匹配地址/blog/post/10/comments
    
    url = "/blog/:post_id|^[0-9]+$" - 匹配地址 /blog/post/3
    
    url = "/blog/:post_name?|^[a-z0-9\-]+$" - 匹配地址 /blog/my-blog-post
    

    可以在参数后面添加一个星号,使用特殊的通配符参数。与常规参数不同,通配符参数可以匹配一个或多个URL段。URL只能包含单个通配符参数,不能使用正则表达式,也可以后跟可选参数。

    url = "/blog/:category*/:slug"
    

    可配置/blog/cw100/design/plan/list
    category: cw100/design/play
    slug: list

    注意:子目录不会影响页面网址 - URL仅使用url参数定义

    相关文章

      网友评论

        本文标题:october cms页面介绍一

        本文链接:https://www.haomeiwen.com/subject/nhbisxtx.html