How to count pages in a “where” statement?
If the result is empty I need to display a specific information.
Thanks.
How to count pages in a “where” statement?
If the result is empty I need to display a specific information.
Thanks.
You can use the len
function for that, like this:
<p>Number of pages in the /post/ section: {{ len (where .Site.RegularPages "Section" "==" "post") }}.</p>
But put it into a varlable:
{{ $posts := (where .Site.RegularPages "Section" "==" "post") }}
{{ $postCount := len $posts }}
Thank you guys. It worked very well.