当前位置: 动力学知识库 > 问答 > 编程问答 >

Ternary in Laravel Blade to apply row class names

问题描述:

I have this report that Im trying to do, but I want to make the rows alternate colors. this is what I tried, but it does not work. What is the correct way to achieve this?

 <div class="row">

{{$rowOrder = "even"}}

@foreach($data as $row)

{{ $rowLine = ($rowOrder = "odd" ? 'even' : 'odd') }}

<div class="col-sm-4 repColumn {{$rowOrder}}">

<span>{{$row->adm_referraldate}}</span>

<span>{{$row->adm_number}}</span>

</div>

<div class="col-sm-4 repColumn {{$rowOrder}}">

<span>{{$row->dmg_nhsnumber}}</span>

<span>{{$row->dmg_firstname." ".$row->dmg_surname}}</span>

<span>{{$row->dmg_dateofbirth." - (".$row->dmg_ageyears.")"}}</span>

<span>{{$row->dmg_sex}}</span>

</div>

<div class="col-sm-4 repColumn {{$rowOrder}}">

<span>{{$row->dmg_nhsnumber}}</span>

<span>{{$row->dmg_firstname." ".$row->dmg_surname}}</span>

<span>{{$row->dmg_dateofbirth." - (".$row->dmg_ageyears.")"}}</span>

<span>{{$row->dmg_sex}}</span>

</div>

@endforeach

</div>

网友答案:

Replace

{{ $rowLine = ($rowOrder = "odd" ? 'even' : 'odd') }}

with

<?php $rowOrder = ($rowOrder == "odd") ? 'even' : 'odd'; ?>

or if you are using a Laravel 5.2 or up

@php($rowOrder = ($rowOrder == "odd") ? 'even' : 'odd')

Do the same for the line {{$rowOrder = "even"}}

If you used the {{$rowOrder = "even"}} it will echo out the result.

网友答案:
{{ $rowLine = ($rowOrder = "odd" ? 'even' : 'odd') }} 

possibly should be

 {{ $rowLine = ($rowOrder == "odd" ? 'even' : 'odd') }}
分享给朋友:
您可能感兴趣的文章:
随机阅读: