cnichte
1
Hi there, I want to count all folders (non recursive - only in “root”) in section-a
from a page in section-b
via shortcode:
content/
└─ -section-a/
├── folder-a/
│ └─ index.md
├── folder-b/
│ └─ index.md
└── _index.md
This Shortcode is called from a page in section-2:
{{< count-folders section="section-a" >}}
This should get me a 2
How do I get it right?
Those folders are page bundles.
layouts/shortcodes/count.html
{{ $p := .Page }}
{{ with .Get 0 }}
{{ with $p.GetPage . }}
{{ $p = . }}
{{ end }}
{{ end }}
{{ (where $p.Pages "BundleType" "ne" "").Len }}
To get a count of the current page’s children (leaf and branch bundles only):
{{< count >}}
To get a count of another page’s children (leaf and branch bundles only):
{{< count "/logical/path/to/page" >}}
I revised the above to only count bundles.
cnichte
4
Thanks, i ll try this. I found a solution that also seem to work:
{{- $section := .Get "section" | default "galleries" -}}
{{ $pages := (where .Site.RegularPages "Section" "==" $section) }}
{{ $pages.Len }}
called like so:
{{< count-folders >}}
{{< count-folders section="section-a">}}