1

I wanted to make my <li> tag active , for that i wanted to check if $category->id == $product->category_id if equals then the class would be active otherwise inactive. How do i do it inside blade? I have done the following way.But i couldn't get proper output.

<li  class="{!! ($category->id == $product->category_id) ? 'active': '' !!}">
1
  • 1
    It's probably just a typo (caregory_id => category_id). Otherwise this should work. Commented Sep 7, 2017 at 15:04

1 Answer 1

2

You're pretty close:

<li  class="{{ ($category->id == $product->category_id ? 'active': '') }}">

You need {{, not {!!. I also fixed a typo with category_id.

Sign up to request clarification or add additional context in comments.

2 Comments

{!! should be fine as well. Not neccessary, but it should work I believe
True. Probably the typo fix then

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.