Data System
Curvea supports JSON data through the src/data folder.
Data can be loaded into templates with @load.
Data folder
src/data
Example:
src/data/site.json
src/data/posts.json
src/data/products/item-one.json
Loading data
@load site
This loads:
src/data/site.json
and exposes it as:
{{ site.name }}
Aliasing loaded data
@load posts as articles
This exposes the loaded value as:
articles
Loading folders
If the source maps to a folder, Curvea loads all .json files in that folder as an array.
Example:
@load products
If src/data/products exists, the result is an array sorted by filename.
Folder item slugs
When loading a folder of JSON files, if an item is an object and does not already contain slug, Curvea adds the file name as slug.
Example:
src/data/products/coffee-cup.json
becomes:
{
"slug": "coffee-cup"
}
plus the JSON file contents.
Wildcard folder map
@load settings/*
This loads JSON files in src/data/settings as a map keyed by file name.
If aliased:
@load settings/* as settings
then the map is available as settings.
Without an alias, keys are merged into the current scope.