Blade inline if and else if statement

mario picture mario · Mar 26, 2017 · Viewed 40.9k times · Source

Is there a syntax to specify inline if and else if statement in Laravel blade template?

Normally, the syntaxt for if and else statement would be :

{{ $var === "hello" ? "Hi" : "Goodbye" }}

I would now like to include else if statement, is this possible?

 {{ $var === "hello" ? "Hi" : "Goodbye" else if $var ==="howdie ? "how" : "Goodbye""}}

Answer

MoPo picture MoPo · Mar 26, 2017

You can use this code in laravel blade:

{{  $var === "hello" ? "Hi" : ($var ==="howdie ? "how" : "Goodbye") }}