tknx
May 20, 2022, 4:51pm
1
Let’s say I have a series of parallel articles:
/posts/01.001.md
/commentary/01.001.md
I would love to link them so that they appear in the same article.
TItle
Post 01.001 content
Commentary 01.001 content
I thought I could maybe use the related articles function, but since they are in different categories, I am not sure I can get it to work.
In my config.yaml, I started here but doubt it would work.
related:
includeNewer: false
indices:
- name: title
weight: 100
threshold: 80
toLower: false
Have you looked into Page Bundles?
/posts/01.001/index.md <-- leaf bundle (or the main page)
/posts/01.001/commentary.md <-- page resource
Or using Data (YAML/TOML/…) to store a page’s commentaries?
Also if you want the post and commentary content files as organized in your original post, you don’t need the Related feature. From the post’s “single” layout, you already know the file name. So do a .GetPage of that same name from the commentaries section.
tknx
May 20, 2022, 5:49pm
4
So how do I pull using the current filename as the input into the with command?
{{ with .Site.GetPage path.Join "/commentary" .File.LogicalName }}
{{ .Content }}
{{ end }}
Got this to work with a bit of modification:
{{ $comment_path := path.Join "/commentary" .File.LogicalName }}
{{ with .Site.GetPage $comment_path }}
{{ .Content }}
{{ end }}
Cool!
If you don’t want to just path.Join
, you can use nested with
and benefit from the relative change of the “dot” scope in each nested with:
{{ $page_base_file_name := .File.BaseFileName }}
{{ if (ne .Section "commentaries") }}
{{ with site.GetPage "/commentaries" }}
{{ with .GetPage $page_base_file_name }}
<h3>Commentaries</h3>
{{ .Content }}
{{ end }}
{{ end }}
{{ end }}
Additionally, look into the _build
front-matter. It will be useful if you don’t want to list all the commentary pages or its section.
system
Closed
May 22, 2022, 6:41pm
7
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.