Conditionals

Conditionals

You can write conditional blocks within Edge templates using the @if, @elseif, and the @else tags. The inner working of these tags is similar to the JavaScript if/else statements.

@if(user)
<p> {{ user.username }} </p>
@end
@if(user.fullName)
<p> Hello {{ user.fullName }}! </p>
@elseif(user.firstName)
<p> Hello {{ user.firstName }}! </p>
@else
<p> Hello Guest! </p>
@end

The unless tag

Alongside the @if tag, you can also use the @unless tag to express not if statements. For example:

With @if tag
@if(!account.isActive)
<p>Please verify your email address to activate the account </p>
@end
With @unless tag
@unless(account.isActive)
<p>Please verify your email address to activate the account </p>
@end

Using the ternary operator

You can write inline conditionals using the JavaScript ternary operator.

<input
class="input {{ hasError ? 'error' : '' }}"
/>