Are symlinks supported for render hooks?

Setup 1.

I have been using symlinks to define a sort of composite page resource. I included a symlink with a ‘magic’ name into a page bundle. The symlink points to a directory containing an image and captions in several languages . This allows to hardcode the symlink’s name in a template, and then the image and the caption in a particular language are used as page resources. This allows to associate an image + caption with a page similarly to how a theme is associated with a Hugo project.

This works.

Setup 2

When, however, I try to play the same trick with render hooks, it doesn’t work (but pretends to :)). I mean, initially the Hugo server picks the {{.Page.Resource.GetMatch ...}} correctly, and I was fooled into writing a blog post about it - embarrassing. However, once the server gets restarted, the resources are not picked anymore. Worse, they are also missing when I build the site.

I didn’t find anything in documentation regarding symlink support, and googling showed me a post from 2015 saying symlinks are not supported in Hugo. So, my questions are:

  • are symlinks supported at all, or my first setup worked just by some weird coincidence?
  • are render hooks supposed to work with symlinks?
  • should I set up some example on Github and report a bug?

I see a lot of different questions, but I’ll answer the one in the headline:

Symlinks are supported for render hook templates (assuming that’s what you refer to) assuming the symlinks are created in the main project. Symlinks are not supported (for security reasons) in themes (or theme components).

Thank you. Your assumptions are right, sorry for a poor wording.

My symlinks are created in the project itself, but the render hook templates that uses them are in theme. Do you mean, I need to move the render hook templates into the main project as well? Anyway, the server behaves erratically: it renders the hook template, showing the image, but then doesn’t when restarted.


I think I found the cause: my symlink source was outside the project directory. Now that the directory with images and captions is inside the project, it works nicely as expected.

Just in case, my Hugo version:

$ hugo env
Hugo Static Site Generator v0.73.0-428907CC/extended darwin/amd64 BuildDate: 2020-06-23T16:37:47Z

I really don’t understand your setup good enough to comment – but a general tip is that you can also do plenty of what symlinks can do via Hugo’s file mounts.

No, file mounts won’t do what I need to (or so I think).
OK, I’ll try to put together an example on GitHub tomorrow.

I was about to create a test setup at GitHub, but then realized it won’t work because of symlinks. This page describes both the setup and the motivation behind it:

(I was writing my notes on using Hugo while learning/testing it and came up with a small tutorial).

It is getting off the topic of the support, but I would like what you think of this idea. In any case, thanks for your time and help.