【问题标题】:Blade view 'has stack' condition刀片视图“有堆栈”条件
【发布时间】:2017-06-22 18:36:19
【问题描述】:

我想从父布局中检查是否有孩子推动了某些东西。

就像我用View::hasSection('section-name')hasSection 方法检查一样。我正在寻找类似的东西:hasStack

目的是这样的:

@if(/* has stack 'foo' */)
    <div id='foo'>
        @stack('foo')
    </div>
@endif

最好的方法是什么?

[Note] 我正在处理 Laravel 5.4

【问题讨论】:

  • “母版”..?
  • @voodoo417 我要扩展的刀片模板。它叫什么名字?
  • 想想,这叫“父布局”^)

标签: php laravel laravel-5 blade laravel-blade


【解决方案1】:

我正在使用 Laravel 7 和以下工作来检查推送的内容:

@if($__env->yieldPushContent('foo'))
   
    <p>There is something in the "foo" stack.</p>

@endif

你可以把它放到custom blade directive:

    Blade::if('hasStack', function($stackName) {
        return !empty(view()->yieldPushContent($stackName));
    });

并像这样使用它:

@hasStack('foo')

    <p>There is something in the "foo" stack.</p>

@endhasStack

请注意 - @end 部分不是指令名称的驼峰式,所以它是@endhasStack,而不是@endHasStack。

【讨论】:

  • 我无法测试您的解决方案是否有效,因为我在 3 年前提出了这个问题,但我验证了答案,希望能对某人有所帮助。
猜你喜欢
  • 2014-11-04
  • 2014-01-17
  • 1970-01-01
  • 1970-01-01
  • 2016-09-09
  • 1970-01-01
  • 2021-08-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多