User57
User57

Reputation: 2505

How to write logic inside HTML tag in laravel Blade

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': '' !!}">

Upvotes: 1

Views: 1593

Answers (1)

Mike
Mike

Reputation: 8877

You're pretty close:

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

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

Upvotes: 2

Related Questions