( ) : Parentheses
Groups part of an expression so it is evaluated first, before the operators around it.
Syntax
{{(expression) operator value}}
Examples
Without parentheses, operators are evaluated by precedence - multiplication before addition.
Data:
builder.WithData("model", new { price = 10, shipping = 5, qty = 2 });
Template:
<p>{{(model.price + model.shipping) * model.qty}}</p>
<p>{{model.price + model.shipping * model.qty}}</p>
<p>{{(model.qty > 1) && (model.price < 20)}}</p>
Output:
30
20
True
Notes
- Parentheses can be nested:
{{((a + b) * c) / d}}. - Use them to make comparisons and calculations clear, even where the precedence would give the same result.
- In an attribute value,
<,>and&are written<,>and&. - Parentheses after a function name are the function’s arguments, e.g.
{{round(model.price * 1.2, 2)}}.