TinyMCE 和 Laravel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31224938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TinyMCE and Laravel
提问by zlotte
I'm trying to use tinyMCE with my Laravel project. The problem is when I store the new article the html tags are not working. They're showing up like a plain text on display on my laravel view:
我正在尝试在我的 Laravel 项目中使用 tinyMCE。问题是当我存储新文章时,html 标签不起作用。它们在我的 Laravel 视图中显示为纯文本:
This is the code implemented in create.blade.php:
这是在 create.blade.php 中实现的代码:
<script type="text/javascript" src="{{ asset('/js/tinymce/tinymce.min.js') }}"></script>
<script type="text/javascript">
tinymce.init({
selector : "textarea",
plugins : ["advlist autolink lists link image charmap print preview anchor", "searchreplace visualblocks code fullscreen", "insertdatetime media table contextmenu paste jbimages"],
toolbar : "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image jbimages",
});
</script>
回答by maiorano84
Markup is escaped by default in Laravel. If you're storing text in your database that contains markup, you will either want to apply a getter to your Eloquent Model that will unescape it for you, or use the following Blade syntax:
默认情况下,Laravel 中的标记会被转义。如果你在你的数据库中存储包含标记的文本,你要么想要将一个 getter 应用到你的 Eloquent 模型,它会为你转义它,或者使用以下 Blade 语法:
{!! $model->text !!}
When dealing with unescaped output, I would highly recommend limiting the tags that can be applied in your TinyMCE editor by using the valid_elementsattribute.
在处理未转义的输出时,我强烈建议使用valid_elements属性来限制可以在 TinyMCE 编辑器中应用的标签。