I have the following structure:
content/projects/
├── project-1/
│ ├── _index.md
│ ├── log-1.md
│ └── log-2.md
└── project-2/
├── _index.md
├── log-3.md
└── log-4.md
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>**
<div>
{{ end }}
I am unable to reproduce the problem with this structure:
content/
├── projects/
│ ├── project-1/
│ │ ├── _index.md
│ │ └── log-1.md
│ └── _index.md
└── _index.md
Perhaps you are missing an _index.md 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:
layouts/
├── _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:
[[cascade]]
type = 'logs'
[cascade._target]
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.