Note that there are some explanatory texts on larger screens.

plurals
  1. POTurning off div wrap for Backbone.Marionette.ItemView
    primarykey
    data
    text
    <p>I'm looking at the Angry Cats Backbone/Marionette tutorial posts here</p> <p><a href="http://davidsulc.com/blog/2012/04/15/a-simple-backbone-marionette-tutorial/" rel="nofollow noreferrer">http://davidsulc.com/blog/2012/04/15/a-simple-backbone-marionette-tutorial/</a></p> <p><a href="http://davidsulc.com/blog/2012/04/22/a-simple-backbone-marionette-tutorial-part-2/" rel="nofollow noreferrer">http://davidsulc.com/blog/2012/04/22/a-simple-backbone-marionette-tutorial-part-2/</a></p> <p>and I came upon the same question/need posted here:</p> <p><a href="https://stackoverflow.com/questions/7894253/backbone-js-turning-off-wrap-by-div-in-render">Backbone.js turning off wrap by div in render</a></p> <p>But I can only get that to work for Backbone.Views, not Backbone.Marionette.ItemViews.</p> <p>For example, from the simple backbone marionette tutorial links above, take AngryCatView:</p> <pre><code>AngryCatView = Backbone.Marionette.ItemView.extend({ template: "#angry_cat-template", tagName: 'tr', className: 'angry_cat', ... }); </code></pre> <p>The template, <code>#angry_cat-template</code>, looks like this:</p> <pre><code>&lt;script type="text/template" id="angry_cat-template"&gt; &lt;td&gt;&lt;%= rank %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= votes %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= name %&gt;&lt;/td&gt; ... &lt;/script&gt; </code></pre> <p>What I don't like, is that the AngryCatView needs to have</p> <pre><code> tagName: 'tr', className: 'angry_cat', </code></pre> <p>-- if I take <code>tagName</code> out, then <code>angry_cat-template</code> gets wrapped by a <code>&lt;div&gt;</code>.</p> <p>What I would like is to specify the HTML in one place (the angry_cat-template) and not have most HTML (all the <code>&lt;td&gt;</code> tags) in angry_cat-template and a little HTML (the <code>&lt;tr&gt;</code> tag) in AngryCatView. I would like to write this in angry_cat-template:</p> <pre><code>&lt;script type="text/template" id="angry_cat-template"&gt; &lt;tr class="angry_cat"&gt; &lt;td&gt;&lt;%= rank %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= votes %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= name %&gt;&lt;/td&gt; ... &lt;/tr&gt; &lt;/script&gt; </code></pre> <p>It just feels cleaner to me but I've been mucking around with Derik Bailey's answer in "Backbone.js turning off wrap by div in render" and can't get it to work for Backbone.Marionette.</p> <p>Any ideas?</p>
    singulars
    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