Commit e121459a authored by Vincent Pelletier's avatar Vincent Pelletier

Document and test the ${{{}}:...} and ${...:{{}}} edge cases.

Test the latter, and document how to work around the former.
parent 59afa85d
...@@ -40,6 +40,7 @@ And according Jinja2 template (kept simple, control structures are possible):: ...@@ -40,6 +40,7 @@ And according Jinja2 template (kept simple, control structures are possible)::
... 'Knights who say "{{knight}}" also protect {{ words | join(", ") }}.\n' ... 'Knights who say "{{knight}}" also protect {{ words | join(", ") }}.\n'
... 'They later say {{later}}\n' ... 'They later say {{later}}\n'
... '${this:is_literal}\n' ... '${this:is_literal}\n'
... '${foo:{{bar}}}\n'
... 'swallow: {{ json_module.dumps(("african", "european")) }}\n' ... 'swallow: {{ json_module.dumps(("african", "european")) }}\n'
... 'parameters from section: {{ param_dict | dictsort }}\n' ... 'parameters from section: {{ param_dict | dictsort }}\n'
... 'Rendered with {{recipe}}' ... 'Rendered with {{recipe}}'
...@@ -57,6 +58,7 @@ And the template has been rendered:: ...@@ -57,6 +58,7 @@ And the template has been rendered::
Knights who say "Ni !" also protect Peng, Neee-wom. Knights who say "Ni !" also protect Peng, Neee-wom.
They later say Ekke Ekke Ekke Ekke Ptangya Ziiinnggggggg Ni! They later say Ekke Ekke Ekke Ekke Ptangya Ziiinnggggggg Ni!
${this:is_literal} ${this:is_literal}
${foo:value}
swallow: ["african", "european"] swallow: ["african", "european"]
parameters from section: [('bar', 'bar'), ('foo', '1')] parameters from section: [('bar', 'bar'), ('foo', '1')]
Rendered with slapos.recipe.template:jinja2 Rendered with slapos.recipe.template:jinja2
...@@ -118,6 +120,16 @@ Optional: ...@@ -118,6 +120,16 @@ Optional:
Jinja2 extensions to enable when rendering the template, Jinja2 extensions to enable when rendering the template,
whitespace-separated. By default, none is loaded. whitespace-separated. By default, none is loaded.
FAQ
---
Q: How do I generate ${foo:bar} where foo comes from a variable ?
A: ``{{ '${' ~ foo_var ~ ':bar}' }}``
This is required as jinja2 fails parsing "${{{ foo_var }}:bar}". Though,
jinja2 succeeds at parsing "${foo:{{ bar_var }}}" so this trick isn't
needed for that case.
Use jinja2 extensions Use jinja2 extensions
~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment