This is my content structure. I want to add 4 counter on home page, each will show how many *.md files in one subsections
content/
section/
subsection1/
_index.md
postA.md
postB.md
subsection2/
_index.md
postC.md
postD.md
subsection3/
_index.md
postE.md
postF.md
subsection4/
_index.md
postG.md
postH.md
I tried the fllowing code
{{ $subsection1 := (where .Site.RegularPages "Section" "==" "subsection1") }}
{{ $subsection1_count := len $subsection1}}
But subsection1_count
return 0
, Is there some way work? Thanks!
You mean that this?
{{ $subsection1 := (where .Site.RegularPages "CurrentSection" "==" "section/subsection1") }}
{{ $subsection1_count := len $subsection1}}
The return value is still 0
on home page! Is there another way?
PS: Each sub-section has own specific template, the _index.md file adjust the type
in front matter
ju52
April 13, 2020, 7:53am
4
you missed the dot!
.CurrentSection
{{ $subsection1 := (where .Site.RegularPages ".CurrentSection" "==" "section/subsection1") }}
ju52
April 13, 2020, 9:37am
6
I think .CurrentSection is “subsection1” etc
try it
range over .Site.RegularPages and print out .Title .Section .CurrentSection
Can you explain it? Hugo Framework, I only know a little.
You can .GetPage
the subsection, then get the len
of its pages:
{{ $sub1 := .Site.GetPage "section/subsection1" }}
{{ $sub1len := len $sub1.Pages }}
Oh~
It works!
I appreciate your helping me, @pointyfar , @ju52 . Thank you very much! Having a nice day!
system
Closed
April 15, 2020, 10:03am
10
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.