2015-10-12 21 views
0

這是我在laravel blade中的html代碼。如何使用handlebar js在laravel 4.2中轉義html?

<script id="expressions-template" type="text/x-handlebars-template"> 
    @{{description.escaped}} 
    @{{example}} 

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

</script> 

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

這是我的js腳本編譯數據

模板
$(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)刀片不逃避HTML標籤,它只是打印html標籤文本。

+0

您是否嘗試用{{!!}替換'{{}}'! !}'? –

+0

永不止息..只爲v5 –

+0

@SandeepNayak它只是打印{!!例如!!}不是html代碼 – Ajanth

回答

0
Blade::setEscapedContentTags('[[', ']]'); 
Blade::setContentTags('[[[', ']]]'); 

對單個視圖使用不同的標籤,您可以在將生成視圖的閉包或控制器操作中設置標籤。

對手柄模板使用花括號。