diff --git a/app/assets/javascripts/discourse/helpers/plugin-outlet.js.es6 b/app/assets/javascripts/discourse/helpers/plugin-outlet.js.es6 index 57739bb93..6b81d23a1 100644 --- a/app/assets/javascripts/discourse/helpers/plugin-outlet.js.es6 +++ b/app/assets/javascripts/discourse/helpers/plugin-outlet.js.es6 @@ -2,6 +2,8 @@ A plugin outlet is an extension point for templates where other templates can be inserted by plugins. + ## Usage + If you handlebars template has: ```handlebars @@ -27,6 +29,16 @@ And it will be wired up automatically. + ## The block form + + If you use the block form of the outlet, its contents will be displayed + if no connectors are found. Example: + + ```handlebars + {{#plugin-outlet "hello-world"}} + Nobody says hello :'( + {{/plugin-outlet}} + ``` **/ var _connectorCache; @@ -77,13 +89,24 @@ export default function(connectionName, options) { var self = this; if (_connectorCache[connectionName]) { - var CustomContainerView = Ember.ContainerView.extend({ - childViews: _connectorCache[connectionName].map(function(vc) { - return vc.create({context: self}); - }) - }); - return Ember.Handlebars.helpers.view.call(this, CustomContainerView, options); - } else { + var view, + childViews = _connectorCache[connectionName].map(function(vc) { + return vc.create({ context: self }); + }); + + // If there is more than one view, create a container. Otherwise + // just shove it in. + if (childViews.length > 1) { + view = Ember.ContainerView.extend({ + childViews: childViews + }); + } else { + view = childViews[0]; + } + return Ember.Handlebars.helpers.view.call(this, view, options); + } else if (options.fn) { + + // If a block is passed, render its content. return Ember.Handlebars.helpers.view.call(this, Ember.View.extend({ isVirtual: true,