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

Post list from taxonomy not working

Started by Muut Archive 10 years ago · 5 replies · 362 views
10 years ago

This is really killing me, but I can't figure out what's going on and any insight would be enormously appreciated. I'm trying to return a list of all posts in a category using:

TWIG
{% for post in taxonomy.findTaxonomy({'category': ['patterns']}) %}
    <tr>
      <td class="title">{{ post.title }}</td>
      <td class="summary">{{ post.summary }}</td>
      <td class="link"><i class="fa fa-rocket"></i> <a href="{{ post.url }}" title="view the {{ post.title }} micro-pattern">view it!</a></td>
    </tr>
  {% endfor %}

There are at minimum 30 posts under that category, but this loop returns nothing. I tried:

TWIG
{% for post in taxonomy.findTaxonomy({'category': 'patterns'}) %}
{% for post in taxonomy.findTaxonomy({'category': [patterns]}) %}

To no avail. I'd even be happy with a list of all posts right now, so I can dwindle it down by specific titles.

Cheers.

10 years ago

This seemed to work for me, maybe you just forgot to add the single quotes around your terms?

TWIG

{{ debug(taxonomy.findTaxonomy({'category': ['patterns']})) }}
---
10 years ago

How are your taxonomies set in the .md-files?

10 years ago

here's my front matter:

YAML
title: Header
taxonomy:
  category: [gui-design, patterns]
  tag: [Brand,PuppetEnterprise,ElapsedTime]

twig_first: true
process:
  twig: true

body_classes: "pattern definition"

status: incomplete

micro_patterns:
  enabled: true
  mpNames: [Buttons,TimeStamp,EmptyTable,LipBalm]
10 years ago

As far as I can tell, there's something odd happening when I call the macro. So I just put the following in the code for the template and it runs fine.

TWIG
{% if header.micro_patterns.enabled %}
          <section class="micro-patterns">
            <header>
              <h3><i class="fa fa-cubes"></i> Micro-patterns</h3>
              <hr>
            </header>
            <article>
              <table class="definition-table">
                <thead>
                  <tr>
                    <th class="title">Title</th>
                    <th class="link">Link</th>
                  </tr>
                </thead>
                <tbody>
                  {% for i, mpost in taxonomy.findTaxonomy({'category': ['patterns']}) %}
                    {% for j, name in header.micro_patterns.mpNames %}
                    {% if (name == mpost.title) %} 
                    <tr>
                      <td class="title">{{ name }}</td>
                      <td class="link"><i class="fa fa-rocket"></i> <a href="{{ mpost.url }}" title="view the {{ mpost.title }} micro-pattern">view it!</a></td>
                    </tr>
                    {% endif %}
                    {% endfor %}
                  {% endfor %}
                </tbody>
              </table>
            </article>
          </section>
        {% endif %}

There might have been some goofiness going on with having nested for loops as well, but the above code works like I need it to - just not from a macro.

10 years ago

Macros are tricky, you have to pass everything to the macro or use global twig variables or they will not be able to access them.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1354 9 years ago
Archive · by Muut Archive, 9 years ago
2 935 9 years ago
Archive · by Muut Archive, 9 years ago
2 4065 9 years ago
Archive · by Muut Archive, 9 years ago
1 2953 9 years ago
Archive · by Muut Archive, 9 years ago
3 1119 9 years ago