Blade template not executing @else clause

I have a Blade template that loads a list of users and displays their various details.

If a user has no mobile number I want to display the message “No Mobile Number” (I’ve tried single and double quotes), this never gets displayed:

@if ($person->Mobile >= "")
    {{ $person->Mobile }}
@else
    'No Mobile Number' 
@endif

I tried substituting the “No Mobile” message with {{ $person->EMail }} (which I’m displaying elsewhere, so I know everyone has an email address), but still go nothing, as far as I can tell the logic isn’t going into the @else block.
Any ideas?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

This should work

@if (!empty($person->Mobile))
    {{{ $person->Mobile }}}
@else
    'No Mobile Number' 
@endif

Method 2

I use this approach:

@if( isset($error_message) )
    @section('content')
        @parent
    @stop
    @section('error_message')
        <strong>Holly molly! </strong><em>{{  $error_message  }} :(</em>
    @stop  
@endif

I have a section content and inside content have another section error_message so if error_message variable is set, show that content section and inside print my error_message.

PD: I haven’t my original code to hand… Im currently using Twig as primary template engine in Laravel4. Twig beats Blade in simplycity and is very usefull


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x