Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Get a collection of all "CHILDREN" but only with a special "TAG"

Started by Pascal Mahlberg 9 years ago · 1 replies · 745 views
9 years ago

I would like to show a collection of all "CHILDREN" pages with a special "TAG"

For now i use this collection:

TWIG
{% set items = page.collection({'items':{'@self.children': '{{item.title}}'}, 'limit': '6','order': {'by': 'default', 'dir': 'asc'}}) %}
      {% for item in items %}
        <a href='{{item.url}}' class='{{item.title|lower|replace({'ä': "ae", 'ö': "oe", 'ü': "ue", 'ß': "ss", '.': "-"})}} cell'>{{item.title}}
        <img src="/images/inspiration/kachel-nav/{{item.title|lower|replace({'ä': "ae", 'ö': "oe", 'ü': "ue", 'ß': "ss"})}}.jpg" alt="">
        </a>
      {% endfor %}

But here i would like to filter these Items only whit the tag: "top"

So i would like to combine @self.children & @taxonomy but i think it will not work.

Any suggestions? Is this possible?

👍 1
9 years ago

I do a similar thing to find all 'featured' posts, here is my Twig:

TWIG
{% for post in taxonomy.findTaxonomy({'tag': "featured"}) %}
 {% include 'partials/blog_item.html.twig' with {'page':post, 'truncate':true} %}
{% endfor %}

And here is another method I use:

TWIG
{% for child in collection %}
  {% if "featured" in child.taxonomy['tag'] %}
    {% include 'partials/blog_item.html.twig' with {'blog':page, 'page':child, 'truncate':true} %}
  {% endif %}
{% endfor %}

Maybe the above might be of help?

last edited 10/25/17 by Paul Hibbitts

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 76 8 hours ago
General · by pamtbaau, 13 hours ago
1 47 13 hours ago
General · by Andy Miller, 1 day ago
0 44 1 day ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 40 5 days ago