Supported expression syntax
ultraq opened this issue · 5 comments
A list of the expression syntaxes currently supported in the latest version of ThymeleafJS. The full list of expression syntaxes was taken from the Thymeleaf docs here: https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#standard-expression-syntax
Simple expressions
- Variable Expressions:
${...}
- Selection Variable Expressions:
*{...}
- Message Expressions:
#{...}
- Link URL Expressions:
@{...}
- Fragment Expressions:
~{...}
Complex expressions
- Iteration expressions
Literals
- Text literals:
'one text'
,'Another one!'
,... - Number literals:
0
,34
,3.0
,12.3
,... - Boolean literals:
true
,false
- Null literal:
null
- Literal tokens:
one
,sometext
,main
,...
Text operations
- String concatenation:
+
- Literal substitutions:
|The name is ${name}|
Arithmetic operations
- Binary operators:
+
,-
,*
,/
,%
- Minus sign (unary operator):
-
Boolean operations
- Binary operators:
-
&&
-
and
-
||
-
or
-
- Boolean negation (unary operator):
-
!
-
not
-
Comparisons and equality
- Comparators:
-
>
-
<
-
>=
-
<=
-
gt
-
lt
-
ge
-
le
-
- Equality operators:
-
==
,===
-
!=
,!==
-
eq
-
ne
-
Conditional operators
- If-then:
(if) ? (then)
- If-then-else:
(if) ? (then) : (else)
- Default:
(value) ?: (defaultvalue)
Special tokens
- No-Operation:
_
The message expression is one that would be really handy.
I will have a look on how we can implement it
How would we do a .substring now?
I think you can do a .substring
on any string now as both Java and JavaScript both call that method "substring". I haven't tried it with that method in particular, but being able to do method calls on objects is already possible.
alright!
Hi, I have a problem
let templateEngine = new TemplateEngine({
...STANDARD_CONFIGURATION,
messageResolver: async (key, parameters) => resolveMessage(key, lang, 'defaultMessage')
})
const context = {
user: user
}
templateEngine.processFile(fileName, context)
, it work on tags loike this with #
, but not on variable expressions
<p th:text="#{email.activation.greeting(${user.firstName})}">
Dear
</p>
, this results in - Dear{0}
The templates I have worked fine with spring thymeleaf
Did I forget something ?