A. Apola
A. Apola

Reputation: 131

How do we concatenate using blade template engine Laravel

I am new to Laravel and don't know if it is possible at all to concatenate a string to a blade variable.

I want to display the name of the author with the ~ sign concatenated to the author's name from the left. Here is my code.

<div class="author">~{{ $quote->author or '' }}</div>

What I want is if the author is set, it should be displayed with the ~. How do I concatenate this? Thanks for any help

Upvotes: 0

Views: 1680

Answers (2)

Jamal Abdul Nasir
Jamal Abdul Nasir

Reputation: 2667

This would be better

<div class="author">~{{ isset($quote->author) ? $quote->author : '' }}</div>

UPDATE:

<div class="author">{{ isset($quote->author) ? '~'.$quote->author : '' }}</div>

Upvotes: 1

Raymond Cheng
Raymond Cheng

Reputation: 2495

<div class="author">
    @if (isset($quote->author))
     ~ {{ $quote->author }}
    @else 
    @endif
</div>

https://laravel.com/docs/5.3/blade#control-structures

Upvotes: 0

Related Questions