Skip to content

Latest commit

 

History

History
50 lines (36 loc) · 1.78 KB

block.adoc

File metadata and controls

50 lines (36 loc) · 1.78 KB

block

since version 1.0.0

block is a macro that can be used to enclose a block of macros. The common practice is to use it with the # starting character. That way the macros inside the block are evaluated, but their output is dropped. The macro block always result an empty string. It is used to have the state-altering effects of the macros without the output.

Note
block has a similar functionality as comment. It is recommended to use the comment macro with the @ starting character. Jamal does not interpret the macro content in that case. Use the block with # to have the content interpreted. block should be used to enclose definitions to a scope level.

When defining macros inside a block, do not forget to export them if you want to use them outside the block. The macro can be used with the option flat (also aliased as export) since the release 2.3.0. In this case, Jamal will automatically export all the macros defined inside the block.

Examples:

Jamal source
{@block it is like comment {@define x=1} is not evaluated}
{#block it is like comment {@define x=1}{@define y=1} is evaluated{@export y}}
x is not exported, value is not defined: "{?x}" <-- empty string
y is exported, value is defined: "{y}" <-- not empty string, it is 1
{#block [flat] {@define H=1}{@define K=1} exports automatically}
H is exported, value is defined: "{H}" <-- not empty string
K is exported, value is defined: "{K}" <-- not empty string, it is 1

results in:

output
x is not exported, value is not defined: "" <-- empty string
y is exported, value is defined: "1" <-- not empty string, it is 1

H is exported, value is defined: "1" <-- not empty string
K is exported, value is defined: "1" <-- not empty string, it is 1