Skip to content

Commit b8ce945

Browse files
authored
Merge pull request #48370 from mkouba/docs-qute-let-opt-end
Qute ref guide: Let section - mention optional end tag
2 parents 4e66327 + 77ba0b9 commit b8ce945

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

docs/src/main/asciidoc/qute-reference.adoc

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,19 +1006,39 @@ The following operators are supported in `is`/`case` block conditions:
10061006
[[let_section]]
10071007
==== Let Section
10081008

1009-
This section allows you to define named local variables:
1009+
This section allows you to define named local variables.
10101010

1011+
.Let
10111012
[source,html]
10121013
----
10131014
{#let myParent=order.item.parent isActive=false age=10 price=(order.price + 10)} <1><2>
10141015
<h1>{myParent.name}</h1>
10151016
Is active: {isActive}
10161017
Age: {age}
1018+
Price: {price}
10171019
{/let} <3>
10181020
----
10191021
<1> The local variable is initialized with an expression that can also represent a <<literals,literal>>, i.e. `isActive=false` and `age=10`.
10201022
<2> The infix notation is only supported if parentheses are used for grouping, e.g. `price=(order.price + 10)` is equivalent to `price=order.price.plus(10)`.
1021-
<3> Keep in mind that the variable is not available outside the `let` section that defines it.
1023+
<3> Variables are not available outside the `let` section.
1024+
1025+
The variables are not available outside the defining `let` section.
1026+
However, the end tag is optional, if missing then the section ends where the parent section ends.
1027+
1028+
.Let with optional end tag
1029+
[source,html]
1030+
----
1031+
<ul>
1032+
{#for item in items}
1033+
{#let price=item.price} <1>
1034+
<li>{price}</li>
1035+
{! a synthetic {/let} is added here automatically !}
1036+
{/for}
1037+
</ul>
1038+
{price} --> BOOM! <2>
1039+
----
1040+
<1> The local variable `price` is initialized with expression `item.price`.
1041+
<2> Variable `price` is not available outside the `let` section.
10221042

10231043
If a key of a section parameter, such as the name of the local variable, ends with a `?`, then the local variable is only set if the key without the `?` suffix resolves to `null` or _"not found"_:
10241044

0 commit comments

Comments
 (0)