How to determine a page budle, branch, or leaf?

Hi. I’ve gone through the docs a fair bit and googled but unable to figure out how to determine is page is a Bundle, Branch, or Leaf.

Does anyone know if there something like if .IsPage Bundle or Leaf of if Page.type or something. I couldn’t find anything.

The only thing I found so far was this. Trying to wrap my head around it now. https://godoc.org/github.com/spf13/hugo/resources/page

You could try {{ .File }}:

With a regular page at yoursite.com/posts/foo/, you could have either foo.md (not a bundle) or index.md (is a bundle)

So you could bundle this into a partial and have a return value:

{{ if .File }}                        foo.md or index.md or _index.md    
  {{ if .IsPage }}                    foo.md or index.md
    {{ $file := print .File }}
    {{ if in $file "index.md" }}      index.md
      page bundle {{$file}}
    {{ else }}
      NOT a page bundle {{ $file }}   foo.md
    {{ end }}
  {{ else }}                          _index.md
    branch bundle: {{ .File }} 
  {{ end }}
{{ else }}
  Probably automatically-generated list .Page: {{ .IsNode }} <br>
{{ end }}
2 Likes

Thanks I also just found this. There is an example here similar to that. Thank you.

In case anyone else wants to know, I had to do this in a shortcode, and .File will not work there and throw errors.

Please use {{ $.Page.File }} instead for shortcode templates.

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