Get direct parent of a child in a subsection

I have the following structure:

├── project-1/
│   ├──
│   ├──
│   └──
└── project-2/

I am listing all the logs like this. For each child (log-1, log-2, etc) I want to also display a link to its direct parent section (log-2 → project-1, log-4 → project2, etc). However, when I do {{ $log.Parent }} all I get is the topmost section, projects.

{{ $logs := (where (where .Site.Pages "Section" "projects") "Params.is_log" true)}}
{{ range $index, $log := $logs }}
    <div class="log">
         **<a href="">{{ $log.Parent }}</a>**
 {{ end }}

I am unable to reproduce the problem with this structure:

├── projects/
│   ├── project-1/
│   │   ├──
│   │   └──
│   └──

Perhaps you are missing an file in one of the project directories.

Also, instead of setting is_log = true in the front matter of each log file, you might consider setting type = 'logs' instead. That would make it easy to create a single page template that is unique to logs:

├── _default/
│   ├── baseof.html
│   ├── home.html
│   ├── list.html
│   └── single.html
└── logs/
    └── single.html

And if your log files have a consistent name pattern (e.g., they begin with “log”), you can set the .Type in your site configuration instead of adding front matter to each file:

type = 'logs'

path = '/projects/*/log*.md'

Either way, your page selection is reduced to:

{{ $logs := where site.RegularPages "Type" "logs" }}

I created a blank project with the same exact content structure. For whatever reason it works exactly as I expect on the new one. Are there any projects settings that might affect this behavior?

I also appreciate the feedback on the style. The is_log was a poor solution.

As soon as I posted I found what was causing all of my grief. My past self had this in my config.toml

disableKinds = ['taxonomy', 'term']

Get rid of this line in case you added it like I did.

I can’t see how that would have any effect.

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