Compare commits

...

2 commits

Author SHA1 Message Date
sdomi
ec0238f76f docs: document the template boolean set 2025-04-06 07:02:05 +02:00
sdomi
be23e31362 template: implement set statements 2025-04-06 06:57:21 +02:00
2 changed files with 19 additions and 0 deletions

View file

@ -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 `<a href="{{-uri-2}}meow">(...)</a>`, 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-<name>}}` |
| In the code | n/a |
| Notes | Very simple, processed out of order, nesting in conditional statements will not work. |
If `{{-set-<name>}}` exists anywhere within your processed template (including the included templates),
`array[?<name>]` will get set internally. This can be used to conditionally enable parts of another template
based on what other templates are loaded.

View file

@ -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