From c5bd9be47fbb4155b3f24e5cdb90fb54dac53010 Mon Sep 17 00:00:00 2001
From: wing328
To access the first or last element in a list using Mustache:
-{{#vars}}{{#-first}} this is the first element {{.}} {{/-first}}{{/vars}}
-{{#vars}}{{#-last}} this is the last element {{.}} {{/-last}}{{/vars}}
-
+{{#vars}}{{#-first}} this is the first element {{.}} {{/-first}}{{/vars}}
+{{#vars}}{{#-last}} this is the last element {{.}} {{/-last}}{{/vars}}
+
Mustache evaluates template variables contextually. If the variable isn't found in the immediate object, mustache will search the parent. This is similar to JavaScript's prototype object (if you're familiar with the concept).
You can inspect this entire context by outputting {{this}}
. For example:
To access the first or last element in a list using Mustache:
-{{#vars}}{{#-first}} this is the first element {{.}} {{/-first}}{{/vars}}
-{{#vars}}{{#-last}} this is the last element {{.}} {{/-last}}{{/vars}}
-
+{{#vars}}{{#-first}} this is the first element {{.}} {{/-first}}{{/vars}}
+{{#vars}}{{#-last}} this is the last element {{.}} {{/-last}}{{/vars}}
+
Mustache evaluates template variables contextually. If the variable isn't found in the immediate object, mustache will search the parent. This is similar to JavaScript's prototype object (if you're familiar with the concept).
You can inspect this entire context by outputting {{this}}
. For example: