Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically choosing a view at runtime with Ember + Handlebars
    primarykey
    data
    text
    <p>I am using Ember, Ember Data, and Handlebars to display a timeline with a number of different types of models. My current implementation, though functioning properly, seems like it could be drastically improved with a convention and a helper. However, I can't figure out how to use already defined templates.</p> <p>This is what I have:</p> <pre><code>{{#view App.AccountSelectedView contentBinding="App.selectedAccountController.everythingSorted"}} {{#with content}} &lt;ol class="timeline"&gt; {{#each this}} {{#is constructor="App.Design"}} ... stuff about the design {{/is}} {{#is constructor="App.Order"}} ... stuff about the order {{/is}} {{#is constructor="App.Message"}} ... stuff about the message {{/is}} {{/each}} &lt;/ol&gt; {{/with}} {{/view}} </code></pre> <p>...along with a helper...</p> <pre><code>Handlebars.registerHelper('is', function(options) { if (this.constructor == options.hash["constructor"]) { return options.fn(this); } }); </code></pre> <p>I would rather rely on some convention to figure out what view to render. For example:</p> <pre><code>&lt;script type="text/x-handlebars-template" data-model="App.Design" id="design-view"&gt; ... stuff about the design &lt;/script&gt; &lt;script type="text/x-handlebars-template" data-model="App.Order" id="order-view"&gt; ... stuff about the order &lt;/script&gt; </code></pre> <p>Perhaps the data-model attribute could be used to determine how an object is rendered.</p> <pre><code>{{#view App.SelectedAccountView contentBinding="App.selectedAccountController.everythingSorted"}} {{#with content}} &lt;ol class="timeline"&gt; {{#each this}} {{viewish this}} {{/each}} &lt;/ol&gt; {{/with}} {{/view}} </code></pre> <p>Alas, I can't figure out how to access templates from a helper.</p> <pre><code>Handlebars.registerHelper('viewish', function(options) { // Were I able to access the templates this question // would be unnecessary. // Handlebars.TEMPLATES is undefined... }); </code></pre> <p>Also, is this something I should want to do with Handlebars?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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