douke9379 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">
   @{{description.escaped}}
   @{{example}}

   @{{description.unescaped}}
   @{{{example}}}

</script>

<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
  $('.content-placeholder').html(theCompiledHtml);

 });

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?