2015-10-12 05:47
浏览 44

如何使用车把js在laravel 4.2中转义html?

This is my html code in laravel blade.

<script id="expressions-template" type="text/x-handlebars-template">



<div class="content-placeholder"></div>

This is my js script for compile the template with data

$(function () {
 // Grab the template script
 var theTemplateScript = $("#expressions-template").html();

 // Compile the template
 var theTemplate = Handlebars.compile(theTemplateScript);

 // Define our data object
 var context={
   "description": {
      "escaped": "Using {{}} brackets will result in escaped HTML:",
      "unescaped": "Using {{{}}} will leave the context as it is:"
   "example": "<button> Hello </button>"

 // Pass our data to the template
 var theCompiledHtml = theTemplate(context);

 // Add the compiled html to the page


laravel (4.2) blade does not escape html tags, its just print html tags as text.

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duan33360 2015-10-13 06:16
    Blade::setEscapedContentTags('[[', ']]');
    Blade::setContentTags('[[[', ']]]');

    use different tags for a single view, you can set the tags in the closure or controller action that will generate the view.

    Use curly braces for handlebar templates.

    解决 无用
    打赏 举报

相关推荐 更多相似问题