Last week I started a blog series about Statiq, a static content generator written in C#. The next major post will focus on creating a Statiq theme and template.

When creating a theme or even just using Statiq, you can create a settings file many different ways. One way is to use YAML. YAML, short for Yet Another Markup Language, has become extremely popular over the past few years for front matter on markdown files and also for settings. Typically, the settings or data is easier to read. In fact, this post has some front matter in YAML. If you looked at this file in GitHub, you could see that. Here’s a snippet:

1
2
3
title: Nested YAML Settings in Statiq
author: Jason Gaylord
date: 2023-05-18

Looking at this example above, you may want to have nested settings in YAML. Here’s an example below:

1
2
3
4
5
title: Nested YAML Settings in Statiq
author:
  firstName: Jason
  lastName: Gaylord
date: 2023-05-18

Using the format above, there’s only a single instance of author. So, you can access this property or setting using a C# expression like this:

1
string firstName = Context.GetString("author:firstName");

However, there are times that you may want to have multiple instances of a property. Here’s a sample YAML snippet:

1
2
3
4
5
6
7
title: Nested YAML Settings in Statiq
authors:
  - firstName: Jason
    lastName: Gaylord
  - firstName: Dr
    lastName: Seuss
date: 2023-05-18

This is a bit different. In this case, we can access a specific first name by using the collection index like so:

1
string firstName = Context.GetString("author:0:firstName");

Hopefully this little tip helps as you read in nested settings.