Hugo

Check if page exists

Hello.

I just started learning Hugo and found this problem:

I have 3 boxes each with parameter “link” to the other page. How can I check if url in .Params.link is correct? I want to set href="#" if page from link don’t exists (don’t want 404 in this case).

OR how can i transform param link = “pages/something.md” to url in template ({{< ref .Params.link >}} do not work)? I assume in this case i can check fileExists?

Hi,

you can try and use .GetPage https://gohugo.io/functions/getpage/ to check if the page exists.

Not sure if this suits your use case but you also can use RelRef shortcode

Thank you, i don’t know how i missed that in docs.