Allowing access to globals while in a loop

This used to make a name like DATA.0.STR.  Since bash doesn't like using
multi-dimensional arrays, we can shortcut things and just assume that
STR referes to the global variable here.

This closes issue #7
This commit is contained in:
Tyler Akins 2015-08-27 09:42:01 -05:00
parent 70cc736b4a
commit e623b16bb8
4 changed files with 15 additions and 1 deletions

2
mo
View File

@ -111,7 +111,7 @@ mustache-find-string() {
# $2: Context name
# $3: Desired variable name
mustache-full-tag-name() {
if [[ -z "$2" ]]; then
if [[ -z "$2" ]] || [[ "$2" == *.* ]]; then
local "$1" && mustache-indirect "$1" "$3"
else
local "$1" && mustache-indirect "$1" "${2}.${3}"

View File

@ -0,0 +1,2 @@
STR=abc
DATA=(111 222)

View File

@ -0,0 +1,6 @@
Issue #7
abc
Item: 111
String: abc
Item: 222
String: abc

View File

@ -0,0 +1,6 @@
Issue #7
{{STR}}
{{#DATA}}
Item: {{.}}
String: {{STR}}
{{/DATA}}