Note that there are some explanatory texts on larger screens.

plurals
  1. POEmber.js: Dynamically switching layouts with outlets
    primarykey
    data
    text
    <p>I'm trying to dynamically switch between layouts in Ember.js by having one outlet named layout in ApplicationView, and several layout classes with an unnamed outlet inside of it. See this JSfiddle: <a href="http://jsfiddle.net/ElteHupkes/SFC7R/2/" rel="nofollow noreferrer">http://jsfiddle.net/ElteHupkes/SFC7R/2/</a>.</p> <p>This works fine the first time, however upon toggling the layout the content disappears. This seems to be the same problem that occurs when you simply re-render the application view (<code>router.get('applicationView').rerender()</code>), making this question somewhat related to my other one earlier: <a href="https://stackoverflow.com/questions/13009470/re-rendering-applicationview-with-outlet">Re-rendering ApplicationView with outlet</a>.</p> <p>I would say that as the controller bindings stay the same, the unnamed outlet should still be connected and the inner view contents should thus be rendered. I'm hoping someone can enlighten me as to why they aren't :).</p> <p>HTML:</p> <pre><code>&lt;script type="text/x-handlebars" data-template-name="application"&gt; {{outlet layout}} &lt;a href="#" {{action doToggleLayout}}&gt;Toggle layout&lt;/a&gt; &lt;/script&gt; &lt;script type="text/x-handlebars" data-template-name="layout1"&gt; &lt;h1&gt;Layout 1&lt;/h1&gt; {{outlet}} &lt;/script&gt; &lt;script type="text/x-handlebars" data-template-name="layout2"&gt; &lt;h1&gt;Layout 2&lt;/h1&gt; {{outlet}} &lt;/script&gt; &lt;script type="text/x-handlebars" data-template-name="index"&gt; Page contents. &lt;/script&gt; </code></pre> <p>JS:</p> <pre><code>App = Ember.Application.create({ autoinit: false, Router: Ember.Router.extend({ root: Em.Route.extend({ index: Em.Route.extend({ route: '/', connectOutlets: function(router) { // Fire toggle once as an initializer router.send('doToggleLayout'); router.get('applicationController').connectOutlet('index'); } }), doToggleLayout: function(router) { this.set('layoutClass', this.get('layoutClass') == App.Layout2View ? App.Layout1View : App.Layout2View); router.get('applicationController').connectOutlet({ viewClass: this.get('layoutClass'), outletName: 'layout' }); } }) }), ApplicationView: Em.View.extend({ templateName: 'application' }), ApplicationController: Em.Controller.extend({}) }); App.IndexView = Em.View.extend({ templateName: 'index' }); App.Layout1View = Em.View.extend({ templateName: 'layout1' }); App.Layout2View = Em.View.extend({ templateName: 'layout2' }); App.set('layoutClass', App.Layout2View); App.initialize(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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