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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器