Best way to implement global site settings?

Hi there! I’m new to Netlify CMS and Hugo. So what I’m trying to achieve is to create a “file” collection called “settings” where I can define global variables like site logo, phone, email etc and use it in header and footer on every page of the site. So what is the best way to do this with Netlify CMS and Hugo and how this front matter could be accessed from any site html page?

Here is my example of config.yml

# when using the default proxy server port
local_backend: true

backend:
  name: git-gateway
  branch: master # Branch to update (optional; defaults to master)
media_folder: static/uploads
public_folder: /uploads
collections: # A list of collections the CMS should be able to edit
  - name: "settings"
    label: "Settings"
    files:
      - file: "content/site-settings.yml"
        label: "Global Settings"
        name: "globalSettings"
        fields:
          - {label: "Logo", name: "logo", widget: "image"}
          - {label: "Description", name: "description", widget: "text"}
          - {label: "Google Tag Manager ID", name: "gtm_id", widget: "text"}
          - {label: "Phone", name: "phone", widget: "text"}
          - {label: "Email", name: "mailto", widget: "text"}
          - {label: "Plhtcxt", name: "plhtcxt", widget: "text"}
          - {label: "Country", name: "country", widget: "text"}

I used something like this
{{ .Params.globalSettings.phone }}
{{ .Params.settings.globalSettings.phone }}
{{ .settings.globalSettings.phone }}
… and many many other variations

But this obviously does not work))

I’m no Hugo expert, but I think you have to put the file in data/ instead of content/:

https://bwaycer.github.io/hugo_tutorial.hugo/extras/datafiles/

You can then use the data like so: {{.Site.Data.settings.description}} (if I interpreted the docs correctly)

3 Likes

Actually this looks like a good workaround! Huge thanks! Now it works!

1 Like

Just a side note. I have to rename file to not have a “-” symbol in it, since Hugo can’t see it. Now I use this {{.Site.Data.settings.phone}}

1 Like

I was afraid that would lead to a bit of trouble, but wasn’t sure. Glad you’ve got it working!

1 Like

Thanks a lot!! This worked for me like a charm!

1 Like