Blade template not executing @else clause

社会主义新天地 提交于 2019-12-25 01:32:37

问题


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?


回答1:


This should work

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



回答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



来源:https://stackoverflow.com/questions/17631445/blade-template-not-executing-else-clause

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!