diff options
| author | Benjamin Linskey | 2026-06-07 02:15:36 -0400 |
|---|---|---|
| committer | Benjamin Linskey | 2026-06-07 02:15:36 -0400 |
| commit | c23b240bc382af4f97eb9cb9bada8b32180c341b (patch) | |
| tree | 915d626fe5fb599d38ee0a4d56ef1fa60f74cb9d | |
| parent | 0cd3a0bacd54eecf2a1339dd99120fc0c3280a88 (diff) | |
| download | tpl-c23b240bc382af4f97eb9cb9bada8b32180c341b.tar.gz | |
Allow vars to reference vars defined earlier
The template variable syntax can be used when defining a variable to reference the value of a previously defined variable:
foo = bar
baz = {{ foo }}
| -rwxr-xr-x | template | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -3,7 +3,17 @@ BEGIN { FS = "[[:space:]]*=[[:space:]]*" } FILENAME == ARGV[1] && /^#/ { next } -FILENAME == ARGV[1] && NF == 2 { vals[$1] = $2 } +FILENAME == ARGV[1] && NF == 2 { + # If the value is a template variable that matches a previously defined + # variable, use that variable's value. Otherwise, use the literal + # value. + if (match($2, /\{\{[[:space:]]*[^\{\}[:space:]]+[[:space:]]\}\}/)) { + match($2, /[^\{\}[:space:]]+/) + vals[$1] = vals[substr($2, RSTART, RLENGTH)] + } else { + vals[$1] = $2 + } +} FILENAME == ARGV[1] { next } /\{\{[[:space:]]*[^\{\}[:space:]]+[[:space:]]*\}\}/ { |