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

时间:2016-01-02 19:49:03

标签: php laravel octobercms

我正在尝试使用Rainlab博客插件在10月CMS上创建一个博客,在我的类别页面上,我想将当前类别的名称作为标题。我无法弄清楚如何做到这一点,文档中没有关于获取当前类别的内容,谷歌也找不到它。

1 个答案:

答案 0 :(得分:3)

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

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

    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>
相关问题