Data files in the page bundle

I had a need to use a data file in a page bundle and found this page. However, when I attempted to use the above as an example, I got:
execute of template failed: template: index.html:40:25: executing “main” at <.Resources.Get>: can’t evaluate field Get in type resource.Resources

For anyone else who stumbles across this:

Per the Page Resources docs, it looks like .Resources.Get should actually be .Resources.GetMatch

Note that if you are doing this within a Custom Shortcode instead of within a standard Template, then you need .Page.Resources.GetMatch, or .Parent.Page.Resources.GetMatch if this is a nested Shortcode, since Shortcodes have their own context and use .Page to get to the page’s context.

If you search for .Resources.Get, you will find resources.Get in the Hugo Pipes docs. This is a separate and unrelated feature for accessing files in the global /assets/ directory.

1 Like