0

レンダリングされない Underscore.js のテンプレートがあります。私の問題はこの JSFiddleで説明されています。

// this string will get loaded by an ajax call and put in a variable when the application starts
var allTemplates = '<section id="header">header template</section>    <section id="content"><% var test = 10 %><%= test %></section>"';

// put it in the DOM to parse it with jQuery
$('#test').html(allTemplates);




var getSpecificTemplate = function(templateID) {
    return $('#test').find('#' + templateID).html();   
};

var templateData = getSpecificTemplate('content');

// expected log output: 10
// actual log output: &lt;% var test = 10 %&gt;&lt;%= test %&gt; 
console.log( _.template(templateData, {}) );

// why?

このセットアップは、私のコードとほとんど同じです。何が問題なのですか?テンプレートがエンコードされているのはなぜですか?

4

2 に答える 2