title: Dynamically render partial templates using mustache
body: <p>Is there a way to dynamically inject partial templates (and have it work the same way in both Ruby &amp; Javascript)? Basically, I'm trying to render different types of objects in a list.</p>
  
  <p>The best I can come up with is this:</p>
  
  <pre><code>&lt;div class="items"&gt;
  {{#items}}
  &lt;div class="item"&gt;
    {{#is_message}}
    {{&gt; message}}
    {{/is_message}}
  
    {{#is_picture}}
    {{&gt; picture}}
    {{/is_picture}}
  &lt;/div&gt;
  {{/items}}
  &lt;/div&gt;
  </code></pre>
  
  <p>I'm not super-psyched about this approach.
  Is there a better way?</p>
  
  <p>Also note that the different types of models for the views can have non-similar fields. I suppose I could always go to the lowest common denominator and have the data hash contain the html, however I would rather use the mustache templates.</p>