Answer the question
In order to leave comments, you need to log in
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
{{ $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 questionAsk a Question
731 491 924 answers to any question