Skip to content

Commit

Permalink
* Updated syntax.md for @with to describe the multiple arguments option
Browse files Browse the repository at this point in the history
  • Loading branch information
mreuvers committed Jan 13, 2017
1 parent 3dd5dc8 commit 12a6825
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions docs/SYNTAX.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ Note that Rocker has intelligence to skip template content that includes ```{```
and ```}``` characters such as JavaScript or CSS. You will not need to escape
these characters as long as you have matching left and right curly brackets.

### With blocks (set a variable) (@with)
### With blocks (set one or more variables) (@with)

As of v0.12.0 a `@with` block sets a variable to a value within a scoped block. Once the block
exits the variable is no longer available. Variable names cannot conflict with
exits the variable is no longer available. Variable names cannot conflict with
other variable names (e.g. arguments) and they will be checked by the Java compiler.

For Java 8 (note this is statically typed and checked at compile time)
Expand All @@ -194,6 +194,24 @@ For Java 6/7
@with (String s = list.get(0)) {
@s
}

As of v0.15.0 a @with block can set more than one variable within the scoped block. Once the block
exits the variables are no longer available. Variable names cannot conflict with
other variable names (e.g. arguments) and they will be checked by the Java compiler.

For Java 8 (note this is statically typed and checked at compile time)

@with (s1 = list.get(0), s2=map.get("key").subList(0,3)) {
@s1
@s2.get(0)
}

For Java 6/7

@with (String s1 = list.get(0), List<String> s2=map.get("key").subList(0,3)) {
@s1
@s2.get(0)
}

### Null-safe with blocks (@with?)

Expand All @@ -214,6 +232,9 @@ Since `list.get(0)` returns null and the `?` presence operator was added to
incredibly powerful to add prefixes and postfixes to data that may or may not
exist.

Note: Nullsafe with blocks are not allowed if the with block has multiple arguments.
Doing so will result in a compile error.

### Eval expression (@())

As of v0.13.0 a `@( )` expression will evaluate the expression between the
Expand Down

0 comments on commit 12a6825

Please sign in to comment.