0

For the given view, in 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);

What do I need to add to the "body" property to make "Line one." appear on a line above "Line Two." once rendered?

Note: templateHelpers became templateContext in newer versions of Marionette.

Experiments: <br> does not work. It is simply shown as plaintext.

Caleb Jay
  • 2,159
  • 3
  • 32
  • 66

1 Answers1

0

The reason <br> didn't work is due to Handlebars, not Marionette. As per this stack overflow question, to make Handlebars not escape html expressions, use {{{}}} triple braces, instead of {{}}. Thus, the following code works:

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);
Caleb Jay
  • 2,159
  • 3
  • 32
  • 66
  • 1
    This is close. The {{{ is not needed in the body string it is need in the template string around `{{{ body }}}` in the `compile` function. The string itself can just be "Line one.
    Line Two."
    – Paul Falgout Jul 18 '17 at 14:01