Skip to content

Instantly share code, notes, and snippets.

@phish108
Created July 19, 2017 19:25
Show Gist options
  • Save phish108/4edf320c20c4c4234eafd93c15620be6 to your computer and use it in GitHub Desktop.
Save phish108/4edf320c20c4c4234eafd93c15620be6 to your computer and use it in GitHub Desktop.
Mustache Templates with Dot Notation

Mustache and cross referrencing the context

Sometimes it is useful to have distinct pointers to an element in a different part of the context but don't want to start a new section. In this case the dot notation is your friend.

The dot-notation allows to reference a sub entries that are reachable without traversing a list.

This GIST has been tested with javascript mustache.

{
"i10n": {
"string1": "hello",
"string2": "world"
},
"data": [
{
"id": 10,
"name": "ten",
"sub": {
"name": "zen"
}
},
{
"id": 11,
"name": "elf",
"sub": {
"name": "elv"
}
},
{
"id": 12,
"name": "deck",
"sub": {
"name": "zwelf"
}
}
]
}
{{#i10n}}
- {{string1}}
- {{string2}}
{{/i10n}}
{{i10n.string1}}
{{#data}}
{{i10n.string1}} {{name}} {{sub.name}}
{{/data}}
- hello
- world
hello
hello ten zen
hello elf elv
hello deck zwelf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment