jrenk
jrenk

Reputation: 1416

Set Background Color of a <td> in a @if in Blade Templating

I have a Table cell like this:

<td>
    @if ($user->status == 1)Present
    @elseif ($user->status_detail != null) Absent(see Details)
    @else Absent
    @endif
</td>

So my problem is, I don't want to just give the Table cell the Word "Present" I want to give it also a Color. Do you guys have a suggestion for this problem?

Upvotes: 0

Views: 3226

Answers (4)

Elasek
Elasek

Reputation: 123

<td class="status">
@if ($user->status == 1)Present
@elseif ($user->status_detail != null) Absent(see Details)
@else Absent
@endif
</td>

CSS

.status{ background:#fff;}

or should it be different when absent or present?

Upvotes: -1

Varun Victor
Varun Victor

Reputation: 100

Give a tag around the text "Present". then give a class to the span use CSS to give background color to span.

<td>
    @if ($user->status == 1)<span class="present">Present</span>
    @elseif ($user->status_detail != null) Absent(see Details)
    @else <span class="absent">Absent</span>
    @endif
</td>

In CSS

.present{ background:#ff0;display:block; width:100%;}
.absent{ background:#f00;display:block; width:100%;}

Upvotes: 1

Sougata Bose
Sougata Bose

Reputation: 31749

@if ($user->status == 1) 
   $status = Present;
   $color = "green";
@elseif ($user->status_detail != null) 
   $status = Absent(see Details);
   $color = "red"
@else
   $status = Absent(see Details);
   $color = "red";
@endif

<td style="background-color:{{$color}}">{{$status}}</td>

Upvotes: 0

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111869

You need to add this in element as in the following example

<td class="
@if ($user->status == 1)
present
@else
absent
@endif
">
    @if ($user->status == 1)Present
    @elseif ($user->status_detail != null) Absent(see Details)
    @else Absent
    @endif
</td>

And then in CSS you can define styles as you want for example:

.present {background:#0f0;}
.absent {background:#f00;}

Upvotes: 3

Related Questions