我正在尝试使用Rainlab博客插件在十月CMS上创建一个博客,我想在我的类别页面上放上当前类别的名称作为标题。我想不出该怎么做,文档中没有关于获取当前类别的内容,谷歌也找不到它。
只需在类别模板中使用{{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>