In one of my projects, I faced a similar issue. I needed to create a form dynamically, i.e the form would contain different field views that could not be determined prior runtime. I needed the fields to be Marionette views because they had pretty complicated behaviour.
The way I have done it in Marionette 1.4 in CoffeeScript
:
class Module.AdditionalOptionsLayout extends Marionette.Layout
tagName: 'form'
initialize: (options = {}) ->
@_fieldViews = options.fieldViews || []
onRender: ->
@_showFields @_fieldViews
_showFields: (fieldViews) ->
fieldViews.forEach (fieldView) => @_addRegion().show fieldView
_addRegion: ->
regionClass = _.uniqueId('field-region__')
@$el.append $("<div class=\"#{regionClass}\"></div>")
@addRegion regionClass, '.' + regionClass
Please, let me know if it needs further explanation or I can clarify this in JS. I am also aware that it is a late answer, however, hope somebody could find it still useful. Also, note - the answer is relevant only for Marionette 1.x