首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >十月CMS Rainlab博客插件获取当前类别名称?

问十月CMS Rainlab博客插件获取当前类别名称?
EN

Stack Overflow用户
提问于 2016-01-03 03:49:03
回答 1查看 3.1K关注 0票数 1

我正在尝试使用Rainlab博客插件在十月CMS上创建一个博客,在我的类别页面上,我想把当前类别的名称作为标题。我不知道该怎么做,文档中没有任何关于获取当前类别的内容,Google也无法为我找到它。

EN

回答 1

Stack Overflow用户

发布于 2016-02-24 09:25:04

只需在类别模板中使用{{ category.name }}就可以了。

如果您没有自定义类别模板(并且使用插件中的默认模板),那么您需要在主题中添加一个。我的是这样的:

代码语言:javascript
复制
    title = "Blog Category"
    url = "/blog/category/:slug/:page?"
    layout = "default"

    [blogPosts]
    categoryFilter = "{{ :slug }}"

    ==
    function onEnd()
    {
        // Optional - set the page title to the category name
        if ($this->category)
            $this->page->title = $this->category->name;
    }
    ==

    <div class="container blog-category">
        <div class="row">
            <div class="col-md-8 col-md-offset-2">

                        {% if not category %}
                            <h1>Category not found</h1>
                        {% else %}
                            <h1>{{ category.name }}</h1>

                    {% for post in posts %}

                    {% partial "blog/list-single" post=post %}

                    {% else %}

                        <div class="no-data">{{ noPostsMessage }}</div>

                    {% endfor %}

                        {% endif %}

                    </div>
            </div>
    </div>
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34570027

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档