Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

Collection Being Looped Through Twice

Started by Caylon Mc 6 years ago · 2 replies · 442 views
6 years ago

Happy New Years everyone.

So, I'm using Grav as a hobby and I am running into an issue - after updating from the last version my collection on a page looks like it is being run through twice in my For Each.

The folder structure is

TXT
Posts
|-- Mobile
|   |-- Mobile Post 1
|   |-- Mobile Post 2
|-- Pc
    |-- Pc Post 1
    |-- PC Post 2

On the posts file I have the header defined as :

YAML
title: Posts
process:
   twig: true
   markdown: false
twig_first: true
never_cache_twig: true
content:
   items: '@self.descendants'
   filter:
     non-visible: true
     type: item
   order:
      by: date
      dir: desct
   limit: 12
   pagination: 'true'

I've tried changing between .descendants and .children

and then the page code is:

TWIG
{% for p in page.collection %}
  <h2>{{ p.title|e }}</h2>
  {{ p.summary|raw }}
{% endfor %}

Thank you for any help!

last edited 01/01/21 by pamtbaau
6 years ago

Found the cause but not exactly - I was trying the bootstrap4 theme and the current version of it was causing this. The issue is not present in any other theme and the collections display properly.

6 years ago

@cfas,

I cannot reproduce the issue. I've:

  • installed theme Bootstrap4,
  • created a folder structure similar to yours and
  • added the frontmatter + code to /pages/02.posts/blog.md

The Posts page both shows a correct blog list of all descendants and show a correct list of children inside the pages content.

Question:

  • Is there a specific reason why you create a list of posts inside a page's content, instead of letting a template create the list?
last edited 01/01/21 by pamtbaau

Suggested topics

Topic Participants Replies Views Activity
Support · by webmasterodp, 1 week ago
4 169 1 week ago
Support · by nwhitfield, 1 week ago
2 145 1 week ago
Support · by stell, 3 weeks ago
5 379 2 weeks ago
Support · by gravinator, 1 month ago
5 571 2 weeks ago
Support · by Gravver, 3 weeks ago
6 356 3 weeks ago