I’m quite new to Hugo (after a couple of years on Jekyll).
I’d like to insert an internal link inside the /layouts/partials/footer.html file.
This link would lead to a page named colophon located at content/colophon/colophon.md.
All my attempts have been fruitless.
Here they are:
The first line of code I inserted was:
[colophon]{{< ref "/colophon/colophon.md" >}}
It yielded an ERROR message in the terminal:
parse failed: template: partials/footer.html:18: unexpected “<” in command
Ditto with:
[colophon]({{< relref “colophon.md” >}})
I renamed the file colophon.html and successively tried:
There may be other things going on in addition to these issues, but you should try in your layout/... file, to add this:
<a href="/colophon/colophon/">Link to Colophon</a>
and it worked!
Still, I don’t fully understand why /colophon/colophon did the job without the .md suffix. Any suggestion for some documentation about this would be most welcome!
That’s because you want to link to the generated page, not the input file. The content file colophon.md does not exist in the published site, only the generated files do.
Hugo takes your content (i.e. *.md files) as input, and uses the layout files to figure out how to create the published HTML files.
Think of the content files as ingredients, the layout files as the recipe, and the published website as pancakes. After Hugo has assembled the ingredients in the way it is described in the recipe, all you will see is the final pancakes; you don’t see the flour independently of the milk.
Note that there are many ways to accomplish the same thing in Hugo.
If, for example, you didn’t want to hard-code the URL to the page you want to link to (for instance if the URL is likely to change, but the content filename is not), the following should get you similar results: