【问题标题】:Laravel Blade template not parsing html?Laravel Blade 模板不解析 html?
【发布时间】:2016-12-21 13:25:31
【问题描述】:

Laravel 新手,目前正在使用 Blade 模板系统。我在解析html时遇到问题。我的数据库中有带有 HTML 标记 (<p>words words words....) 的文本数据,当我使用 {!! $post->content !!} 时,结果与显示的标记相同。我尝试清除缓存甚至 3 个括号 {{{ $post->content }}},但它不起作用。

【问题讨论】:

标签: laravel laravel-blade


【解决方案1】:

当您编写 {{ $post->content }} 时,它不会起作用。它将显示 html 标记。 但是如果你写 {!! $post->content !!} 它不应该显示 html 标签,但它当然不显示换行符。所以你需要在下面写这个 -

{!! nl2br($post->content) !!}

它将换行符转换为
标签。这应该可以正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-28
    • 2015-04-30
    • 2015-09-12
    • 2016-12-18
    • 2014-11-19
    • 2017-09-10
    • 2013-07-21
    • 2016-04-14
    相关资源
    最近更新 更多