Laravel @yield 显示带有 HTML 标签的内容
Laravel @yield showing content with HTML tags
我是 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>
这是截图:
有人可以帮我知道这是怎么回事吗?
@Mousa Alfhaily,您不必使用 html 标签传递 return 值
如果您想分段 return 值...那么您可以在呈现内容的地方执行此操作
@yield('content',"<p>This is a great starting point for new custom pages</p>")
应该是
@yield('content')
那么你的
@section('content')
$var = "This is a great starting point for new custom pages";
<p>
{{$var}}
</p>
@endsection
在 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>")
如果 'content' 部分不可用, 将提供 默认 文本显示在屏幕上。 此文本已转义,因此您会看到 html 标签。
@section
指令,定义一段内容,而@yield
指令用于显示给定段的内容。
所以,如果你有 @section 喜欢- @section('paragraph')
...@endsection
.
那么,@yield 一定是 - @yield('paragraph')
Example
在@yield
指令中-
@yield('content')
在 @section
指令中-
@section('content')
...
your html content
...
@endsection
我是 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>
这是截图:
有人可以帮我知道这是怎么回事吗?
@Mousa Alfhaily,您不必使用 html 标签传递 return 值 如果您想分段 return 值...那么您可以在呈现内容的地方执行此操作
@yield('content',"<p>This is a great starting point for new custom pages</p>")
应该是
@yield('content')
那么你的
@section('content')
$var = "This is a great starting point for new custom pages";
<p>
{{$var}}
</p>
@endsection
在 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>")
如果 'content' 部分不可用,将提供 默认 文本显示在屏幕上。 此文本已转义,因此您会看到 html 标签。
@section
指令,定义一段内容,而@yield
指令用于显示给定段的内容。
所以,如果你有 @section 喜欢- @section('paragraph')
...@endsection
.
那么,@yield 一定是 - @yield('paragraph')
Example
在@yield
指令中-
@yield('content')
在 @section
指令中-
@section('content')
...
your html content
...
@endsection