Make .GetPage send a warning or error about wrong file path

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 }}
1 Like

my case, I have pages/ 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.