如何制作一个列表页面,其结果基于两个ContentTypes的过滤器?
示例:
books:
name: Books
singular_name: Book
relations:
authors:
multiple: false
categories:
multiple: false
authors:
name: Authors
singular_name: Author
categories:
name: Categories
singular_name: Category
如何列出由作者和类别过滤的图书?
/books/(category_slug)/(author_slug)/
好的,我找到了一个"解决方案"路线:
books:
path: /books/{slug}/{author}
_controller: Bolt\Controllers\Frontend::record
contenttypeslug: categories
author: all
然后我就可以同时访问/books/foo
和/books/foo/bar
。
在模板中,我可以author
到达app.request.attributes.get('author')
。
现在问题是如何通过两个ContentTypes获取/过滤books
...
好吧,我最后会到达这个过滤器,不知道是否是最好的方式,看起来不像:
{% set author_slug = app.request.attributes.get('author') %}
{% set books = category.related('books') %}
{% for book in books %}
{% set author = book.related('authors')[0] %}
{% if author_slug == author.slug or author_slug == 'all' %}
My filtered book {{ book.title }}
{% endif %}
{% endfor %}