Twig 螺栓CMS-列出分类选项的每个记录
我试图得到每个分类法选项的列表,在每个分类法选项下面是使用该分类法选项的记录 这是我想要的最终结果: 家人/朋友/家Twig 螺栓CMS-列出分类选项的每个记录,twig,taxonomy,bolt-cms,Twig,Taxonomy,Bolt Cms,我试图得到每个分类法选项的列表,在每个分类法选项下面是使用该分类法选项的记录 这是我想要的最终结果: 家人/朋友/家 诗1 诗2 Cath 诗3 诗4 诗5 政治 诗6 诗7 这是taxonomy.yml: poems: name: Poems slug: poems singular_name: Poem singular_slug: poem behaves_like: categories options: { familyfriendsho
诗1
诗2
Cath
诗3
诗4
诗5
政治
诗6
诗7 这是taxonomy.yml:
poems:
name: Poems
slug: poems
singular_name: Poem
singular_slug: poem
behaves_like: categories
options: { familyfriendshome: "Family/Friends/Home", cath: "Cath", politics: "Politics", observations: "Observations", whimsical: "Whimsical", other: "Other" }
has_sortorder: true
这是contenttypes.yml
poems:
name: Poems
singular_name: poem
behaves_like: categories
fields:
slug:
type: slug
uses: name
name:
label: Title of Poem
type: text
placeholder: e.g., The Way You Look Tonight
sortname:
label: Name for Sorting
type: text
placeholder: This won't be visible on the site - it's just for sorting
date:
label: Date written
type: text
placeholder: e.g., August 2017
text:
type: html
height: 300px
#options:
#ckeditor:
#removeButtons: 'Format,Styles,Font,Outdent,Indent,RemoveFormat,Source'
listing_template: poemsTEST.twig
record_template: poemdetail.twig
taxonomy: [ poems ]
file_under: poems
recordsperpage: 300
default_status: published
这是到目前为止我在清单模板中得到的:
<ul>
{% for poem in app.config.get('taxonomy/poems/options') %}
<li>{{ poem }}
{% setcontent allpoems = 'poems' where { options: 'cath' } printquery %}
<ul>
{% for poem in allpoems %}
<li>
<a href="{{ poem.link }}">{{ poem.title }}</a>
</li>
{% endfor %}
</li>
</ul>
{% endfor %}
</ul>
它列出了每一条记录并忽略了选项
我是在问不可能的事吗
提前谢谢
凯斯
p、 这是我以前应该注意到的。backend Poems overview页面的布局正是我想要的(带有has_sortorder:true in taxonomy.yml)——分类法的名称,然后所有使用该分类法的诗歌都可以直接使用分类法“Poems”
<ul>
{% for poem_taxonomy_term in app.config.get('taxonomy/poems/options') %}
<li>{{ poem_taxonomy_term }}
{% setcontent allpoems = 'poems' where { poem: poem_taxonomy_term } printquery %}
<ul>
{% for poem_record in allpoems %}
<li>
<a href="{{ poem_record.link }}">{{ poem_record.title }}</a>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
{app.config.get('taxonomy/poems/options')中poem\u taxonomy\u术语的百分比%}
- {{诗歌{分类}术语}
{%setcontent allpoems='poems'其中{poems:poems\u taxonomy\u term}printquery%}
{所有诗%中的诗\ U记录的%}
-
{%endfor%}
{%endfor%}
哦,快乐#三个儿子去营救。这几乎是完美的——每个分类法都列出了,只有使用过该分类法的诗歌。还有待完成-如果没有使用分类法(观察和其他),它仍然会出现(下面没有诗)
{app.config.get('taxonomy/poems/options')%中的poem_taxonomy_术语的poem_taxonomy_desc%
- {{诗歌{分类}
{%setcontent allpoems='poems%}
{所有诗%中的诗\ U记录的%}
{%if(poem_-record.taxonomy['poems']['/poems/'~poem_-taxonomy\u-term])%}
-
{%endif%}
{%endfor%}
{%endfor%}
@jadwigo-这是我应该从文档中解决的问题吗
非常感谢您的关注,@Jadwigo,但它给了我同样的结果。我得到了分类项目,下面列出了每首诗(不管它使用哪种分类法)。啊,我无法在真正的螺栓安装上测试这一点,所以这解释了为什么它不起作用。您必须将setcontent行更改为
{%setcontent allpoems='poems',其中{poems:poems\u taxonomy\u term}printquery%}
,因为分类法必须是复数:文档中没有这样的解决方案。。。您需要对此进行一点优化。当你有很多诗歌时,它会为每个分类法选项再次加载所有诗歌。如果将行{%setcontent allpoems='poems%}
移动到第一行
之前,则只会加载一次。检查记录中的现有分类法,行为{%if(poem_record.taxonomy['poems']['/poems/'~poem_taxonomy_term])}
非常紧凑。如果在config.yml中启用strict\u variables:true
,此行将中断您的站点。在小型网站上使用它可能还可以。
<ul>
{% for poem_taxonomy_term in app.config.get('taxonomy/poems/options') %}
<li>{{ poem_taxonomy_term }}
{% setcontent allpoems = 'poems' where { poem: poem_taxonomy_term } printquery %}
<ul>
{% for poem_record in allpoems %}
<li>
<a href="{{ poem_record.link }}">{{ poem_record.title }}</a>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
<ul>
{% for poem_taxonomy_term, poem_taxonomy_desc in app.config.get('taxonomy/poems/options') %}
<li>{{ poem_taxonomy_desc }}
{% setcontent allpoems = 'poems' %}
<ul>
{% for poem_record in allpoems %}
{% if (poem_record.taxonomy['poems']['/poems/' ~ poem_taxonomy_term]) %}
<li>
<a href="{{ poem_record.link }}">{{ poem_record.title }}</a>
</li>
{% endif %}
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>