Skip to content

Commit

Permalink
Allow not to negate, doesn't produce syntax error in HTML fragments…
Browse files Browse the repository at this point in the history
… in Eclipse
  • Loading branch information
brett-smith committed Mar 17, 2024
1 parent 0f3459b commit 33a2d3f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,14 @@ And the Java.
model.condition("feelingFriendly", false);
```

Conditions can be negated by prefixing the name with either a `!` or the more XML syntax friendly `not`.

```html
<t:if !feelingFriendly>
<p>Humbug!</p>
</t:if>
```

If no such named condition exists, then checks will be made to see if a *Variable* with the same name
exists. If it doesn't exist, the condition will evaluate as `false`. If it does exist however, then
it's result will depend on the value and it's type.
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/sshtools/tinytemplate/Templates.java
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,9 @@ private Condition(boolean negate, String name) {
}

private static Condition parse(String cond) {
if(cond.startsWith("!"))
if(cond.startsWith("not"))
return new Condition(true, cond.substring(4));
else if(cond.startsWith("!"))
return new Condition(true, cond.substring(1));
else
return new Condition(false, cond);
Expand Down

0 comments on commit 33a2d3f

Please sign in to comment.