Where .Site.RegularPages "Section" not returning results

I’m trying to access the documents in the v* folders like so:

{{- $xVersion := index (findRE `v\d+\.\d+\.x` .RelPermalink) 0 }}
{{- $docs       := where .Site.RegularPages "Section" $xVersion }}

source: containerd.io/themes/containerd/layouts/partials/docs/sidebar.html at doc_hosting · haddscot/containerd.io · GitHub

content/docs structure:

/Users/haddscot/workplace/containerd.io % tree content/docs
content/docs
├── _index.md
├── architecture.md
├── getting-started.md
├── v1.2.x
│   ├── _index.md
│   └── docs
│       ├── ...
├── v1.3.x
│   ├── _index.md
│   └── docs
│       ├── ...
├── v1.4.x
│   ├── _index.md
│   └── docs
│       ├── ...
├── v1.5.x
│   ├── _index.md
│   └── docs
│       ├── ...
├── v1.6.x
│   ├── _index.md
│   └── docs
│       ├── ...
└── v1.7.x
    ├── _index.md
    └── docs
        ├── ...

… however, the where call is returning nothing. I thought that having an _index.md file in a directory made it a section?

I tried replacing the search argument with “docs/1.7.x”, “1.7.x”, etc. but I can’t get $docs to populate.

Use the like operator with the where function. See documentation.

thanks for replying so fast. however I’m still returning no results:

{{- $docs := where .Site.RegularPages "Section" "like" `v1\.7\.x` }}
returns:
Screenshot 2024-03-07 at 10.19.01 AM

{{- $docs := where .Site.RegularPages "Section" "like" `docs` }}
returns:
[see next reply – new users can only post one image per post I guess]

.Section refers to the top level section. Look at .CurrentSection.

https://gohugo.io/methods/page/currentsection/

{{- $docs := where .Site.RegularPages "Section" .CurrentSection }} still returns nothing, whereas {{- $docs := where .Site.RegularPages "Section" .Section }} returns everything under content/docs/

when I read the value of {{ .CurrentSection }} from the URL http://localhost:1313/docs/v1.7.x/docs/getting-started/ I get Page(/docs/v1.7.x), but when I read {{ .Section }} it just returns docs. is the issue that I need the /docs/v1.7.x unwrapped from the Page()? why would .CurrentSection return a different type from .Section?

If you look at the docs, CurrentSection returns a page reference, while Section returns a string. So you need to compare to a string.

{{ range where site.RegularPages "CurrentSection.Path" "like" `/docs/v\d+\.\d+\.x` }}

Something like the above should work.

You can always work your way there by testing things out:

  {{ range site.RegularPages }}
    <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
    {{ .CurrentSection.Path }}
    {{ .CurrentSection.Title }}
    {{ .CurrentSection.File.Dir }}
    etc.
  {{ end }}

I got it to work with

{{- $docs := where site.RegularPages "CurrentSection.Path" (printf "%s%s" "/docs/" $xVersion) }}

thanks a ton.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.