2

I try like this :

@for($i = 0; $i < 5; $i++) 
...
    <div class="image ($i==0) ? 'image-main' : ''">
...
@endfor

But it does not work.

It seems the way of writing is incorrect.

How can I solve this problem?

LF00
  • 27,015
  • 29
  • 156
  • 295
moses toh
  • 12,344
  • 71
  • 243
  • 443

4 Answers4

3

In laravel's blade file you need to use {{}} to execute php code.

{{ ($i == 0) ? 'image-main' : '' }}
LF00
  • 27,015
  • 29
  • 156
  • 295
  • If you have free time. Maybe you can help me. Look at this : https://stackoverflow.com/questions/44174515/how-can-i-edit-json-element-by-sub-json-value – moses toh May 25 '17 at 09:18
2

You need to use {{ }}

@for($i = 0; $i < 5; $i++)
    ...
    <div class="image {{ ($i==0) ? 'image-main' : '' }}">
    ...
@endfor
Sandeesh
  • 11,486
  • 3
  • 31
  • 42
1
<div class="{{ ($i == 0) ? 'image-main' : '' }}"></div>
Sagar Jajoriya
  • 2,377
  • 1
  • 9
  • 17
1

try with this,

@for($i = 0; $i < 5; $i++) 
    <div class="image{{ ($i==0) ? 'image-main' : '' }}">
@endfor