This course covers the basics of using Hugo - Static Site Generator. Work your way through the articles and we'll teach you everything you need to know to create a professional and scalable website or blog!

Data Templates

Lesson 20
Author : Mike Dane
Last Updated : September, 2017

Data is the backbone of any good website. Often times, even with a static site, there will be certain information that you want to store separate from your actual content files. Hugo makes it really easy to store static data in custom TOML, YAML or JSON files. This data acts as a type of database that hugo partials and layouts can pull information from.

All Hugo data is stored in the Data folder at the root of the site. You can think of the data folder as a kind of mini, read only database.

Creating a data file

Creating a data file is easy, you simply create a TOML, YAML or JSON file inside the Data folder. Then put all the data you want inside the file. It’s smart to group similar data in the same file as it will make it easier to access in the next step.

TOML, YAML, JSON

All three of these formats can be used for storing data. For data files in particular it is popular to use JSON format as this is more widely used and accepted on the web than TOML or YAML.

Let’s use an example to illustrate using data in Hugo. Imagine we were creating a travel blog and we had an entire section of content about various States (in the USA) that we’ve visited. There’s a bunch of information about USA States that could be useful for that content, things like state code, capital and latitude and longitude information.

Let’s make a datafile called state-info.json with all of that information and store it in the data folder.