我是 Laravel 的新手,我遇到了这个问题,当我使用 @yield('content') 查看一些 HTML 时,输出将是将其解码为 HTML 的确切联系。
这是我的代码:
@yield('content',"<p>This is a great starting point for new custom pages</p>")
输出是:<p>This is a great starting point for new custom pages</p>
这是截图:
有人可以帮我知道发生了什么事吗?
最佳答案
在 Laravel 中,@yield
指令希望从生成 html 的文件中提取您记下的 @section
。当您拉入 @section
时,它会在页面上被格式化为正确的 html。
所以,如果你有这样的部分:
@section('paragraph')
<p>here is some text</p>
@stop
并在 @yield
语句中提取它:
@yield('paragraph')
这只会输出 html:
here is some text
你用这个做了什么:
@yield('content',"<p>This is a great starting point for new custom pages</p>")
是在“内容”部分不可用时提供显示在屏幕上的默认 文本。 此文本已转义,因此您会看到 html 标记。
关于Laravel @yield 显示带有 HTML 标签的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57538662/