Note that there are some explanatory texts on larger screens.

plurals
  1. POMarionette.js: Should regions replace instead of insert?
    text
    copied!<p>The default behavior of marionette.js is to append a template into the element specified by the regions selector. However, I usually end up having to create a special region type and override the appendHtml function to do a replace instead. </p> <p>That is not too difficult, but why is append the default? </p> <p>I usually will create the layout template with an empty div to specify where the region should go. Then I replace that div with sub template when I show it. </p> <p>I guess am wondering if there I'm missing the design pattern for templates that makes append more intuitive. </p> <p>Thanks for the help.</p> <p>Update:</p> <p>So I usually will have some view for something I want rendered into the page and will want to todd n element onto the page where I want it. I will do javascript that will look something like this:</p> <pre><code>ReplaceRegion = Marionette.Region.extend({ open: function(view){ this.$el.replaceWith(view.el); } }); App = new Backbone.Marionette.Application(); App.addRegions({ myRegion: { selector: "#someRegion", regionType: ReplaceRegion } }; var view = new CoolWidgetView(); App.myRegion.show(view); </code></pre> <p>And then somewhere in my html I'll throw an empty div in the mix where I want my template to show up.</p> <pre><code>&lt;div id="mywidget"&gt;&lt;/div&gt; </code></pre> <p>Now if it is the only child element, I can use a selector that would just be the parent, but that becomes more tricky when the view i'm inserting has siblings. </p> <p>Also, I'm not really asking for a change to the default, as much as I'm wondering if there's a better way to insert items where you would like them in your layouts. I'm still relatively new to the layout and design of these things so anything helps!</p> <p>Thanks Derick for writing great software!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload