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
  • 24,667
  • 25
  • 136
  • 263
moses toh
  • 10,726
  • 57
  • 212
  • 388

4 Answers4

2

You need to use {{ }}

@for($i = 0; $i < 5; $i++)
    ...
    <div class="image {{ ($i==0) ? 'image-main' : '' }}">
    ...
@endfor
Sandeesh
  • 10,718
  • 3
  • 30
  • 42
2

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

{{ ($i == 0) ? 'image-main' : '' }}
LF00
  • 24,667
  • 25
  • 136
  • 263
  • 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
1
<div class="{{ ($i == 0) ? 'image-main' : '' }}"></div>
Sagar Jajoriya
  • 2,365
  • 1
  • 8
  • 16
1

try with this,

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