0

In MarionetteJS, when creating a CollectionView, all the children are automatically separated by line breaks when rendered. I would like the children in a particular CollectionView that I have to be rendered in order without a line break added (effectively replacing the line break with a space).

I've looked through the source code, and am sure that I need to alter one of the functions that is called from the render method of the CollectionView. However, I can't for the life of me figure out what it is that needs to be altered.

To find the function in question, find "Render children views" on this annotated source code page: http://marionettejs.com/annotated-src/backbone.marionette.html If anybody can help me figure out what needs to be altered, I would really appreciate that!

thisissami
  • 15,445
  • 16
  • 47
  • 74

1 Answers1

4

Every view needs to either be handed a DOM element to use as a root or create one itself. You can control what tag an ItemView uses as root with the tagName property. The default is <div> which is a block element and that's why you get linebreaks.

You have a couple of options here, and none of them is editing the Marionette source.

You can either have you view use an inline element (like a <span>) as a root, which is the option I would prefer.

var ItemView = Backbone.Marionette.ItemView.extend({

  template: '#template',

  tagName: 'span'

});

demo

Or you could use CSS to set the root element of your ItemView to display: inline-block.

ivarni
  • 17,658
  • 17
  • 76
  • 92
  • Perfect! Thanks so much. This makes so much sense. I was originally planning on using an `input` tagName, but then was confused about what would happen (since `input` wouldn't have the typical open tag/close tag markup with stuff in between), so instead just used an `input` in the template. I totally overlooked the fact that `div`s are default, and that this automatically creates a line break. Thanks for your help! – thisissami Apr 16 '15 at 09:40