How to make GetPage throw an error if page not found

You can do this:

{{ with site.GetPage "foo" }}
    {{ .Permalink }}
{{ else }}
    {{ errorf "foo page was not found" }}
{{ end }}

You can wrap something like that in a shortcode if you plan to use that from your content pages.

Kind of related (see the source code of the titleref shortcode I describe in that post):

5 Likes