【问题标题】:Laravel Blade, Yield a default partial appears to have stopped working properlyLaravel Blade,Yield a default partial 似乎已停止正常工作
【发布时间】:2017-12-15 19:17:30
【问题描述】:

这之前一直运行良好,但我刚刚更新了所有的作曲家文件,现在我在使用 Laravel Blade 时遇到了一些问题。 Laravel 版本是5.4.28

我有这个部分(calculator/leopardgeckos/partials/ogtags.blade.php):

<link rel="canonical" href="https://reptimatecalculator.com" />
<meta property="fb:app_id" content="1795251550755689">
<meta property="og:url" content="https://reptimatecalculator.com" />
<meta property="og:type" content="website" />
<meta property="og:locale" content="en_GB" />
<meta property="og:title" content="ReptiMate - Leopard Gecko &amp; African Fat Tail Gecko Genetics Calculator" />
<meta property="og:description" content="ReptiMate Calculator was built from the ground up to create an accurate genetics calculator for Leopard Geckos & African Fat Tailed Geckos. You'll get a list of outcomes including percentage chance of recessive genes being carried over, a punnet square of genetics and also a percentage table denoting likelihood of certain combos hatching." />
<meta property="og:image" content="{{ url('images/reptimate-og-image.jpg') }}" />

我试图在我的布局文件中这样调用它:

@yield('ogtags', View::make('calculator.leopardgeckos.partials.ogtags'))

因此,如果在其他模板文件的ogtags 部分中没有设置任何内容,则默认为该部分。

然而,它实际上是把它打印到屏幕上:

我不知道是什么导致了我的错误,这已经有一段时间了。有没有其他人遇到过这种情况?

【问题讨论】:

  • 他们添加了它,因此传递给 yield 的内容被转义,请更新到最新的 laravel 以接收修复。 github.com/laravel/framework/pull/19884
  • @David 如上所述,我今天更新了,这就是我现在遇到这个问题的原因
  • 哦,等一下,也许我需要清除缓存等
  • 不,不走运:(
  • 您是否尝试过仅使用view 而不是View::make?如果它是视图契约的一个实例,它不应该逃避它。

标签: php laravel laravel-5 laravel-5.4


【解决方案1】:

应该是:

new Illuminate\Support\HtmlString(View::make('calculator.leopardgeckos.partials.ogtags')

@yield('ogtags', new Illuminate\Support\HtmlString(View::make('calculator.leopardgeckos.partials.ogtags'))

【讨论】:

  • @yield('ogtags', new Illuminate\Support\HtmlString(View::make('calculator.leopardgeckos.partials.ogtags')))
  • @AndyHolmes 让我们尝试然后评论:|
  • 我的意思是我的回答很好,除了你添加的代码比需要的多之外没有真正的区别
【解决方案2】:

编辑:

我现在正在更新这个,因为 Taylor 已经标记了框架的更新。在 v5.4.28 中有一个标记为 "Escape default value passed to @yield directive" 的更改,在此引用 - https://github.com/laravel/framework/pull/19643

以下内容可能仍然有效,但您应该能够像我在原始问题中那样将ViewView::make(尚未测试)作为第二个参数传递,现在没有任何问题。

我已经设法通过更改这一行来解决这个问题:

@yield('ogtags', View::make('calculator.leopardgeckos.partials.ogtags'))

到:

@yield('ogtags', new Illuminate\Support\HtmlString(view('calculator.leopardgeckos.partials.ogtags')))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-09
    • 1970-01-01
    • 2017-09-04
    • 2012-05-06
    相关资源
    最近更新 更多