2017-06-22 30 views
0

对于给定的观点,在木偶2.4.4:如何在Marionette templateHelper/templateContext中传递换行符?

var view = Marionette.LayoutView.extend({ 
    template: Handlebars.compile('{{body}}'), 
    templateHelpers: function(){ 
    return { 
     body: "Line one. Line Two.", 
    }; 
    } 
}); 

view = new view(); 
MasterView.showChildView('master_content', view); 

什么我需要添加到“身体”属性,以使“一线”。出现在“第二行”上方的一行中。一旦呈现?

注意:templateHelpers在较新版本的Marionette中变成了templateContext。

实验:<br>不起作用。它简单地显示为明文。

回答

0

原因<br>没有工作是由于把手,而不是木偶。根据this stack overflow question,为了使Handlebars不能转义html表达式,请使用{{{}}}三个大括号,而不是{{}}。因此,下面的代码有效:

var view = Marionette.LayoutView.extend({ 
    template: Handlebars.compile('{{body}}'), 
    templateHelpers: function(){ 
    return { 
     body: "Line one. {{{<br>}}} Line Two.", 
    }; 
    } 
}); 

view = new view(); 
MasterView.showChildView('master_content', view); 
+0

这就接近了。在{compile}函数中,{{{在body字符串中是不需要的,它需要在模板字符串中围绕着{{{{body}}}。字符串本身可以是“第一行
第二行”。 –

相关问题