J
J
Jedi2018-02-04 11:56:03
Laravel
Jedi, 2018-02-04 11:56:03

How to write a ternary operator correctly?

{{ $currentRoute == 'home' ? 'class="active"' : '' }}
I write in Lumen. Now I wanted to write an "activator" on the route menu items. The problem is that the operator adds in quotation marks, but it needs to be without. ("class="active"")
What did I write wrong? Give advice, I will be grateful.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jaroslaw Goszowski, 2018-02-04
@PHPjedi

{{ $currentRoute == 'home' ? 'class=active' : '' }} (no quotes in the class name).
But I advise you to write like this: class="{{ $currentRoute == 'home' ? 'active' : null }}" - it will be easier to add another class in the future, if anything.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question