Is this possible? Especially if the indicated file path does not exist or a trailing slash is added.
The path to a section page can have a trailing slash.
This looks first for the path as given, then tries again without the trailing slash.
{{ $path := "/posts/post-1/" }}
{{ with or (site.GetPage $path) (site.GetPage (strings.TrimSuffix "/" $path)) }}
{{ .Title }}
{{ else }}
{{ errorf "Unable to get page %s" $path }}
{{ end }}
2 Likes
my case, I have pages/test.md
and pages.[lang].md
where the result is blank with a trailing slash.
So, unless Iām missing something, the code I posted will handle that.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.