Frontmatter Configuration Merging
As we just learned, each template in the inheritance chain can include JSON frontmatter (between ---json and --- markers). These configurations are merged recursively as the inheritance chain is processed. Initially the configuration (passed to the first template in the chain) corresponds to the config.json of the root application, merged with all the config.json of the profiles it extends.
It is therefore important to understand how the merging works:
-
Atomic values (strings, numbers, booleans) - Later templates overwrite values from earlier templates
-
Maps/Objects - Maps will be processed recursively by merging the properties of each incoming into the outgoing map.
-
Arrays - Values are appended with duplicates removed. For arrays of maps, deduplication uses the id property if present.
This merging behavior allows child templates to extend or override configuration from parent templates. For example, a child template can append additional stylesheets to the styles array. Existing array items coming from inherited templates or profiles are preserved.
We can also override a single property in a nested configuration entry. For example, to disable the navigation buttons in the toolbar, we can use:
This will be recursively merged into the initial features.toolbar entry, resulting in:
For sure there will be edge cases when this kind of property merging is not desirable. The jinks-templates library provides special properties for that (see "$replace").