Skip to content
Myr

[svn] small jinja doc update for "requirements" behavor

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 4fd2ca5 · Browse files · 1 file+29 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+29 added−0 removed

  • other:+29 added−0 removed

1 file+29 added−0 removed

modified:docs/src/designerdoc.txt+29 added
428 unmodified lines
429 {% set foo = 'foobar' %}430 {{ foo }}431432This should ouputput ``foobar``.433434Scopes435======436437Jinja has multiple scopes. A scope is something like a new transparent foil on438a stack of foils. You can only write to the outermost foil but read all of them439since you can look through them. If you remove the top foil all data on that440foil disappears. Some tags in Jinja add a new layer to the stack. Currently441these are `block`, `for`, `macro` and `filter`. This means that variables and442other elements defined inside a macro, loop or some of the other tags listed443above will be only available in that block. Here an example:444445.. sourcecode:: jinja446447 {% macro angryhello name %}448 {% set angryname = name|upper %}449 Hello {{ name }}. Hello {{ name }}!450 HELLO {{ angryname }}!!!!!!111451 {% endmacro %}452453The variable ``angryname`` just exists inside of the macro, not outside of it.454455Defined macros appear on the context as variables. Because of this those are456affected by the scoping too. A macro defined inside of a macro is just available457in those two macros (the macro itself and the macro it's defined in). For `set`458and `macro` two additional rules exist. If a macro is defined in an extended459template but outside of a visible block (thus outside of any block) will be460available in all blocks below. This allows you to use `include` statements to461load often used macros at once.