diff --git a/docs/template.md b/docs/template.md index 19c1a19..1f775ac 100644 --- a/docs/template.md +++ b/docs/template.md @@ -155,3 +155,15 @@ This is very useful when creating menus; Instead of relying on hardcoded values, on *the same URI level*, one can create links such as `(...)`, which will always resolve to the same file; This eliminates a whole class of bugs where trailing slashes would break some poorly-written relative URLs. + +## Set statement + +| | | +| --- | --- | +| In the template | `{{-set-}}` | +| In the code | n/a | +| Notes | Very simple, processed out of order, nesting in conditional statements will not work. | + +If `{{-set-}}` exists anywhere within your processed template (including the included templates), +`array[?]` will get set internally. This can be used to conditionally enable parts of another template +based on what other templates are loaded. diff --git a/src/template.sh b/src/template.sh index 42270b2..f2b7a4b 100755 --- a/src/template.sh +++ b/src/template.sh @@ -38,6 +38,13 @@ function render() { buf+="${subtemplate}" fi + # process special set statements + if [[ "$template"$'\n'"$garbage" == *'{{-set-'* ]]; then + while read key; do + ref["?$key"]=_ + done <<< "$(grep -Poh '{{-set-\K(.*?)(?=}})' <<< "$template")" + fi + local key IFS=$'\n' for key in ${!ref[@]}; do