get

operator fun get(path: String): List<String>?(source)

A helper method that provides convenient map-like query access for fetching (possibly nested) frontmatter values.

Imagine you have the following frontmatter declaration:

title: Title
data:
assets:
images:
- cat.png
- dog.png
font: Roboto

Once parsed into a FrontMatterElement, you can query it like so:

val fm: FrontMatterElement = ...
fm["title"] // returns listOf("Title")
fm["data.assets.images"] // returns listOf("cat.png", "dog.png")
fm["data.assets.images.1"] // returns listOf("dog.png")
fm["data.assets.font"] // returns listOf("Roboto")
fm["key-not-found"] // returns null

If you are sure that you are fetching a scalar value, you can use the single method:

fm.getValue("title").single()

Note that querying a path to a map (e.g. fm["data.assets"] for the case above) will return null and NOT an empty list, as a map is not a scalar nor a list of scalars. If you absolutely need to distinguish between these two cases, use the query method instead.