Can I access the current KEY when iterating in Mustache?
Yes, CFEngine's implementation of mustache includes an extension to be able to
access the current key when iterating.
@ expands the current key being
This example defines
d as a simple json data structure with
=index-2= being top level keys. The mustache template iterates over the entirety
of the structure leveraging
-top- (another cfengine specific extension to
mustache) and prints the key using
@. Note the use of three curly braces. This
is per the mustache spec to ensure that the rendered value is not html escaped
(not usually what you want in the context of rendering configuration files).
R: CFEngine 3.14.0a.4e12fcf75 R: Iterate over -top- and print keys: index-1 index-2