duanmu2941 2018-03-04 00:51
浏览 42

如何在grav中选择我的树枝模板中的所有标签?

I have the following code in my default.html.twig file to display all the titles of the blog pages with the tag : dog:

<ul>
        {% for post in taxonomy.findTaxonomy({'tag':'dog'}) %}
        <li>{{ post.title }}<span>(0)</span></li>
        {% endfor %}
    </ul>

What i would really like to do is find all the tags and not just the dog tag, so i did the following:

<ul>
        {% for post in taxonomy.findTaxonomy({'tag':'all'}) %}
        <li>{{ post.title }}<span>(0)</span></li>
        {% endfor %}
    </ul>

I changed the dog to all , but this does't really give me any results. I checked the documentation here for findTaxonomy , but it does't help much , also in the <span></span> inside the <li> , I would like to show how many articles for this perticular tag have been posted , eg. if there are five articles for the tag popcorn the html spitedd out should be:

<li>popcorn <span>(5)</span></li>. How do i achieve this ?

  • 写回答

1条回答 默认 最新

  • dpleylxzx47207117 2018-03-04 01:10
    关注

    What about not using findTaxonomy and just iterate on all elements like this:

        {% for post in yourCollection %}
            <li>{{ post.title }}<span>(0)</span></li>
        {% endfor %}
    

    Eventually using an "if" statement on post.tag in case you want to check something (defined value, not '', etc).

    评论

报告相同问题?