Counting children of children query for Stats

I would like to have fancy stats overview of childrens children. The blueprint looks like this:

Every day has created subpages as drafts (from frontend user input). As a demo i created a draft from frontend for 12.07.2022

I added the stats section like this to blueprint:

      stats:
        type: stats
        size: huge
        reports:
          - label: Angemeldete Beratungen
            value: "{{ page.children.children.count }}"
          - label: Durchgeführte Beratungen
            value: 

Unfortunately page.children.children doesn’t count the drafts, it should show “1” as there is a children in page 12.08.2022. What would be correct way to get right number of children children in query?

Additional question. Every childrens children has this toggle:

erledigt:
  width: 1/2
  label: Wurde die Beratung durchgeführt?
  type: toggle
  text: 
    - "Nein"
    - "Ja" 

Is there the way to count how much of “Ja” (yes) has been toggled? And add to query it for stats?

  1. Use childrenAndDrafts instead of children
  2. You can filter by that toggle field using filterBy()

when using {{ page.children.childrenAndDrafts.count }} it shows nothing :frowning:

this is folder structure:

In which page is the stats section?

for the stats section you can use

value: {{ site.find("online-beratung").childrenAndDrafts.filterBy('erledigt', true).count }}

@texnixe that would be the page event.overview.de.txt

the simplified structure of folders is like this

- event.overview (the page with stats)    
-- event.page.entry (a time slot)    
--- event.page.registration (a time slot registration via user input in frontend, saved only as drafts and with 'erledigt' toggle)    

-- event.page.entry (another time slot etc...)    
--- event.page.registration    
--- event.page.registration    
--- event.page.registration    

-- event.page.entry (another time slot etc...)    
--- event.page.registration    
--- event.page.registration

@David it doesn’t work :frowning:

Try:

page.index(true).filterBy('intendedTemplate', 'event.page.registration').filterBy('erledigt', true).count()

Hi, this is what I did:

        reports:
          - label: Angemeldete Beratungen
            value: "{{ page.index(true).filterBy('intendedTemplate', 'event.page.registration')->count() }}"
          - label: Durchgeführte Beratungen
            value: "{{ page.index(true).filterBy('intendedTemplate', 'event.page.registration').filterBy('erledigt', true)->count() }}"

and it still doesn’t work hmmmmm

try to replace ->count() with .count

@texnixe has a type in her example.

2 Likes

It should, though.

page.index(true) returns all descendants of the current page, regardless of its status.

So this structure here should be the same as yours (just simplified content file names)

Screen Shot 2022-07-23 at 23.57.19

And when I then add this section in my overview.yml

title: Overview

sections:
  stats:
    type: stats
    size: huge
    reports:
      - label: Angemeldete Beratungen
        value: "{{ page.index(true).filterBy('intendedTemplate', 'registration').count }}"
      - label: Durchgeführte Beratungen
        value: 

I get exactly that one registration page.

True, sorry.

1 Like

Big thanks to both of you @David and @texnixe this indeed works as intended: {{ page.index(true).filterBy('intendedTemplate', 'registration').count }}