Ranging through subpages

I have a page where I want to list the technical talks I’ve given. Each talk may have more than one resource associated with it. I want to create a list of talks with lists of resources.

Here’s my structure

content/
├── talks/
│   ├── _index.md
│   ├── conference1/
│   │   ├── _index.md
│   │   ├── notes.md
│   │   ├── slides.html

I want a to create a template that renders…

<ol>
  <li>
    <h1>Conference Title</h1>
    <p>Description of conference</p>
    <ul>
      <li><a>Notes</a><li>
      <li><a>Slides</a></li>
    </ul>
  </li>
</ol>

I’m pretty new to GoLang. How do I define a range that’s within the conference folders. Here’s what I have:

<ol class="post-list">
	{{ $pag := .Paginate (where .Data.Pages "Type" "talks") }} 
	{{ range $pag.Pages }}
		<li class="talk-item">
	    <h2>{{ .Title }}</h2>
	    <p> {{ .Description}} </p>
	    <ul>
        {{ range .Data.Pages }}
        	<li>
              <a href="{{ .Permalink }}">{{ .Title }}</a>
            </li>
        {{end}}
	    </ul>
	    </li>
	{{ end }}
</ol>

It only renders the title and description for each conference. What would be the proper syntax instead of {{ range .Data.Pages }} on line 8?

Once you’re in a conference you should use .Pages instead of .Data.Pages.

See Page Variables

Also based on this discussion/summary, the .Data prefix to .Data.Pages wouldn’t ever be needed.

1 Like

I think that you’re asking about customizing your list template for a Nested Section, (in this case a Conference).

You can do something like this:

{{- if .Sections -}}
{{- range .Sections -}}
{{- range $i, $e := .Pages -}}
<---Layout for Main Sections---->
{{- end -}}
{{- end -}}
{{- end -}}

And then

{{- range $i, $e := .Pages -}}
<---Layout for Nested Sections---->
{{- end -}}
1 Like

I suppose what I’m asking is how do I get inside of a conference’s folder? I’m looking for it to render something like this:

For this, I need a range of pages inside of conference.

I’d also like to correct that each conference has index.md instead of _index.md

Ookay! That’s your problem. See Page Bundles

This index.md just turned your Section into a RegularPage

Okay, nevermind. The obvious solution is just to define the path as I normally would with slashes. Now my question has become how do I reference the item at the current position in an array I’m iterating over?

I may be on the wrong track but I would think I could do something like
{{ range (where .Pages "Section" "talk/{{ .Params.foldername }}") }} and have
{{ .Params.foldername }} refer to the value defined in the front matter each conference’s _index.md.

No you cannot use this syntax with range. Neither can you define a template for your Nested Section.

But you can render whatever Parameters you need from a Nested Section’s _index.md with what I posted above.

I have the same structure - a section within section and I’m using this in list.html to render either the list of subsections or the .md files if I’m inside a subsection:

{{ range $index, $element := .Sections }}
<!-- subsections list -->
{{ end }}

{{ range .Data.Pages }}
<!-- .md content files -->
{{ end }}

… basically what @alexandros has posted a few posts above, except I’m not explicitly checking for sections.

PS: not sure how to format code snippets…

1 Like

Thank you, @frangipani . That worked well.