0

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

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

Okay, no what I meant was something like this. {{ isset($pref[0]['www']) ? $pref[0]['www'].<br> : '' }} so that the <br> does not print id no value was present, but the way it is here it prints the <br> as text. hence the question above.
Sorry I forget to add brs. I have updated my answer.
1

you can use plain old php

<?php ?>

Comments

1

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.