morne
morne

Reputation: 4189

adding html to a laravel blade conditional

I have this to print an address on a report.

{{ isset($pref[0]['address']) ? $pref[0]['address'] : '' }}
{{ isset($pref[0]['postcode']) ? $pref[0]['postcode'] : '' }}
{{ isset($pref[0]['phone']) ? $pref[0]['phone'] : '' }}
{{ isset($pref[0]['fax']) ? $pref[0]['fax'] : '' }}
{{ isset($pref[0]['www']) ? $pref[0]['www'] : '' }}  

but I want to add a <br> element to it when the array element has a value.
I tried adding it into the ternary operator, but it prints the <br> element as text.

`{{ isset($pref[0]['www']) ? $pref[0]['www'].<br> : '' }}`  

or
{{ isset($pref[0]['www']) ? $pref[0]['www'].'<br>' : '' }}

but it comes through as text and not html

Upvotes: 0

Views: 3907

Answers (3)

Lorenzo Di Prete
Lorenzo Di Prete

Reputation: 11

In blade you can change the if else short in :

@if(isset($pref[0]['address']))
  {{ $pref[0]['address'] }} <br>
@endif


@if(isset($pref[0]['postcode']))
  {{ $pref[0]['postcode'] }} <br>
@endif

...
...
...
...

Upvotes: 1

Al-Punk
Al-Punk

Reputation: 3660

you can use plain old php

<?php ?>

Upvotes: 1

pespantelis
pespantelis

Reputation: 15382

You should use {!! !!} syntax.

{!! isset($pref[0]['address']) ? $pref[0]['address'].'<br>' : '' !!}
{!! isset($pref[0]['postcode']) ? $pref[0]['postcode'].'<br>' : '' !!}
{!! isset($pref[0]['phone']) ? $pref[0]['phone'].'<br>' : '' !!}
{!! isset($pref[0]['fax']) ? $pref[0]['fax'].'<br>' : '' !!}
{!! isset($pref[0]['www']) ? $pref[0]['www'].'<br>' : '' !!}

http://laravel.com/docs/5.1/blade#displaying-data

Upvotes: 3

Related Questions