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標籤文本。
您是否嘗試用{{!!}替換'{{}}'! !}'? –
永不止息..只爲v5 –
@SandeepNayak它只是打印{!!例如!!}不是html代碼 – Ajanth