如何在Marionette templateHelper / templateContext中传递换行符?

时间:2017-06-22 18:34:35

标签: javascript html marionette

对于给定的观点,在Marionette 2.4.4中:

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);

我需要将“body”属性添加到“第一行”中。出现在“第二行”上方的一行上。一旦渲染?

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

实验:<br>不起作用。它只是显示为明文。

1 个答案:

答案 0 :(得分:0)

<br>无效的原因是由于Handlebars,而不是Marionette。根据{{​​3}},要使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);