You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel 9 Blade中CKEditor更新时显示HTML标签问题求助

问题解决:Laravel 9 Blade中CKEditor更新页面显示HTML标签

问题原因

Blade模板的{{ }}语法会自动转义HTML字符,表单验证失败回显旧数据时,{{ old('description') }}会把原始HTML转成实体字符(比如<p>变成&lt;p&gt;),导致CKEditor渲染时显示纯文本标签,而非解析后的富文本内容。

解决方案

1. 修改textarea的旧数据输出方式

将Blade中的转义输出改为非转义输出,用{!! !!}语法替代{{ }},让CKEditor能直接读取原始HTML内容:

<textarea type="text" class="form-control" name="description" id="editor">{!! old('description') !!}</textarea>

如果是编辑页面从数据库读取数据回显,同样使用非转义输出:

<textarea type="text" class="form-control" name="description" id="editor">{!! $yourModel->description !!}</textarea>

2. 确保数据保存逻辑正确

保存数据时直接使用请求中的原始内容即可,无需额外转义处理:

// 控制器保存示例
$model->description = $request->input('description');
$model->save();

3. 可选:优化CKEditor配置(若仍有异常)

如果上述修改后问题依旧,可在CKEditor初始化时添加配置,确保编辑器正确解析HTML:

ClassicEditor
    .create(document.querySelector('#editor'), {
        htmlSupport: {
            allow: [
                {
                    name: /.*/,
                    attributes: true,
                    classes: true,
                    styles: true
                }
            ]
        }
    })
    .then(editor => {
        console.log(editor);
    })
    .catch(error => {
        console.error(error);
    });

内容的提问来源于stack exchange,提问作者Babur Shah Sayer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 10:05:19