resources.ExecuteAsTemplate without referencing


is there a reason why I need to reference the file created by resources.ExecuteAsTemplate to get the file written to the file system during the build? I use it to create Json files that are used by some JavaScript so I would not need to incude/load/reference the json file in the HTML.

<script defer src="{{ index (index .Site.Data.assets "search.js") "src" | relURL }}"></script>
{{- $searchConfig := resources.Get "search/config.json" | resources.ExecuteAsTemplate "search/config.json" . | resources.Minify -}}
<!-- {{ $searchConfig.Permalink }} -->

I would expect that the file is always written to search/config.json but without the “fake” reference using an HTML comment like <!-- {{ $searchConfig.Permalink }} --> the file is not written to the file system…

What makes this even more confusing, this behavior is not documented, and the build passed without a warning or an error. Personally, I spend some time to figure out why the file is not available in the public folder after build.

A resource can be used in a number of ways.

For example some may be outputted inline, others may be converted to different file formats.

Publishing without an explicit reference would be kind of limiting, as in some cases the resource may need to be manipulated and it may be undesirable to have it published by default when for example .ExecuteAsTemplate is called.

Also note that on top of invoking the .Permalink or .RelPermalink of a Resource there is also an undocumented .Publish method.


Thanks for your fast response. Cool, using .Publish works for me and is much cleaner than the fake reference using a comment.

1 Like

We updated the docs a week ago:

Hugo publishes assets to the to the publishDir (typically public ) when you invoke .Permalink , .RelPermalink , or .Publish.


Ah, good to know. Searching for hugo ExecuteAsTemplate will lead you to Creating a resource from template | Hugo what makes it a bit hard to find on the page mentioned by you.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.