【问题标题】:Blade template not executing @else clause刀片模板未执行 @else 子句
【发布时间】:2013-07-11 23:19:37
【问题描述】:

我有一个 Blade 模板,可以加载用户列表并显示他们的各种详细信息。

如果用户没有手机号码,我想显示消息“没有手机号码”(我试过单引号和双引号),这永远不会显示:

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

我尝试用 {{ $person->EMail }} 替换“No Mobile”消息(我在其他地方显示,所以我知道每个人都有一个电子邮件地址),但我仍然什么也没做告诉逻辑不会进入 @else 块。
有什么想法吗?

【问题讨论】:

  • 你的 if 语句似乎有逻辑问题
  • @TryingTobemyselfRahul - 谢谢,真不敢相信我错过了!

标签: laravel laravel-4 blade


【解决方案1】:

这应该可以工作

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

【讨论】:

  • 使用{{{$person->Mobile}}}大括号的任何具体原因??
【解决方案2】:

我使用这种方法:

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

我有一个部分 content 并且内部内容有另一个部分 error_message 所以如果设置了 error_message 变量,则显示该 content 部分和在里面打印我的error_message

PD:我手头没有原始代码...我目前使用 Twig 作为 Laravel4 中的主要模板引擎。 Twig beats 简单城市中的刀片,非常有用

【讨论】:

  • @axrwkr 你需要更多解释吗?或者可能创建新线程以进行更深入的讨论。
  • @axrwkr 我现在就这样做了...并删除了以前的评论...顺便说一句,我目前阻止添加新答案,我不知道为什么?
猜你喜欢
  • 2021-11-07
  • 1970-01-01
  • 2018-02-05
  • 2018-10-03
  • 2014-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-11
相关资源
最近更新 更多