Expressions
- Ternary
{{ x ? y : z }} - Prefix
{{ !xor-x }} - Infix
{{ x * (y + 3) }} - Postfix
{{ x++ }}or{{ x-- }} - Comparison
{{ x == y }} - Function calls
{{ name.split(" ") }} - Logical Expressions
{{ isHome || isContact }}
Ternary
You can use ternary expressions to conditionally render content. Example:
<span>{{ x == 1 ? "yes" : "no" }}</span>The advantage of a "ternary expression" over an "if statement" is that it can be used inside of any other expressions.
Prefix
You can use prefix expressions to negate or invert a boolean value. Example:
<span>{{ !isTall ? "Not tall" : "Is tall" }}</span>
<span>{{ -x }}</span>Infix
You can use infix expressions to perform arithmetic operations. Example:
<ul>
<li>{{ x + y }}</li> {{-- Addition --}}
<li>{{ x - y }}</li> {{-- Subtraction --}}
<li>{{ x * y }}</li> {{-- Multiplication --}}
<li>{{ x / y }}</li> {{-- Division --}}
<li>{{ x % y }}</li> {{-- Modulo --}}
<li>{{ (x + 2) / (y * (4 - c)) }}</li> {{-- Grouped expressions --}}
</ul>Postfix
You can use postfix expressions to increment or decrement a variable. Example:
<span>{{ x++ }}</span> {{-- Increment --}}
<span>{{ x-- }}</span> {{-- Decrement --}}Comparison
Comparison expressions produce a boolean value. Example:
@if(x == 1)
<p>x is 1</p>
@endSupported Operators
All supported operators are listed in the table below:
| Operator | Description |
|---|---|
== | Equal |
!= | Not equal |
> | Greater |
< | Less |
>= | Greater or equal |
<= | Less or equal |
Function Calls
You can use function calls to call functions. Textwire has a few built-in functions that you can use in your templates.
Functions in Textwire are type-specific, which means that you can't call a function on a variable that is not of the same type as the function. For example, you can't call a split function on an integer variable.
Example:
{{ name.split(" ") }}You can read more detail about built-in functions on the Functions Guide page.
Logical Expressions
You can use logical OR (||) and logical AND (&&) expressions to combine boolean values.
@if(admin || owner)
@component('admin-popup')
@end
@if(isSunny && isWarm)
@component('good-weather-widget')
@endLogical expression accepts any literal value and converts it to boolean. Read about Truthy and Falsy Values.
