According to the docs, I can store JSON and TOML files in a data folder in my theme. I can’t figure out how to access it though. If it was stored in the data directory in my project root, I could do something like {{ index .Site.Data.thedata ‘thevalue’ }}, but that’s not working.
current set up: themes/the-theme/data/the-data.json
I hope the op found a solution yet.
Anyone ending here from a search, you need to mount the directory into the data folder.
Be sure to add the default mounts to still be able to use them.
https://gohugo.io/hugo-modules/configuration/#module-config-mounts
.toml example
[module]
# Default Mounts
[[module.mounts]]
source = 'content'
target = 'content'
[[module.mounts]]
source = 'static'
target = 'static'
[[module.mounts]]
source = 'layouts'
target = 'layouts'
[[module.mounts]]
source = 'data'
target = 'data'
[[module.mounts]]
source = 'assets'
target = 'assets'
[[module.mounts]]
source = 'i18n'
target = 'i18n'
[[module.mounts]]
source = 'archetypes'
target = 'archetypes'
# Custom Mounts
[[module.mounts]]
source = '\themes\<themename>\data'
target = 'data'
No, you do not.
The OP’s data file contained a hyphen, making it an invalid identifier. The naming requirements are documented here:
https://gohugo.io/templates/data-templates/#the-data-folder
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.