-
Notifications
You must be signed in to change notification settings - Fork 0
{stache} Template Language
yesme edited this page Feb 9, 2013
·
14 revisions
- value:
- {$val}
- {$.} - refer to the whole context
- {$val.field}: equals to val["field"]
- {$val[expression]}: the expression can be anything. E.g.: given $field="name", $val[field] => $val["name"] => $val.name
- {$../upper_context_val}
- {$/absolute_context_val}
- function:
- unlike values, functions are globally registered
- format: {$func_name(param1, param2, ...)}
- nested function enabled: {$func_name(func2(param1), param2, ...)}
- shortcut for single param function: filter (or say pipe): value|func_name, can be chained
- no block function (see "why" section)
- expression:
- +, -, *, /, %
- no bit operator
- no logic operator
- function call (and filter)
- (, )
- {@keyword ...; @keyword ...}
- controls and their "end" are paired
- context: {@with expression:name}, {@endwith}
- it enables: {@with func(a, b) | filter | filter : name}
- name is optional, if expression is trival or it will not be refered by name in the future
- context v.s field: they are different!
- control flow: {@if expression-statement}, {@elif expression-statement}, {@else}, (@endif}
- it enables: {@if val; @with val}
- loop:
- integer loop: {@for i : [expression, expression]}, {@endfor}
- array: {@for i : [0, val|length]; @with val[i] : elem}, {@endwith; @endfor}
- object: {@for key : val; @with val[key] : elem}, {@endwith; @endfor}
- array and object needs to be treated differently
- inclusion: {: "path/to/{$whatever_value}/abc.html" expression}
- no block (see "why" section)
- no extension (see "why" section)
- how to locate the specific template is language/platform/scenario dependent
- {# ...}