CKEditor: multiple widget templates
<p>I'm currently creating a 'smartobject' widget. In the widgets dialog, the user can choose a 'smartobject', which simply put, generates some html, which should be added to the editor. Here comes the tricky part: the html  sometimes div elements and sometimes simply span elements. In the case of the div variant, the widget should be wrapped in a div 'template'. In the case of a span variant, the widget should be wrapped in a span and the html should be added 'inline'. </p>

<p>In the widgets API I see the following way to define a template:</p>

<pre><code>editor.widgets.add('smartobject', {
                dialog: 'smartobject',
                pathName: lang.pathName,
                template: '&lt;div class="cke_smartobject"&gt;&lt;/div&gt;', // &lt;------

                upcast: function(element) {
                    return element.hasClass('smartObject');
                },

                init: function() {
                    this.setData('editorHtml', this.element.getOuterHtml());
                },

                data: function() {
                    var editorHtml = this.data.editorHtml;

                    var newElement = new CKEDITOR.dom.element.createFromHtml(editorHtml);

                    newElement.copyAttributes(this.element);

                    this.element.setText(newElement.getText());
                }
            });
</code></pre>

<p>But in my case, the template is more dynamic: sometimes a div and sometimes the span will do the correct thing.. </p>

<p>How can I fix this without needing to create two widgets which will do the exact same thing, with only the wrapping element as difference?</p>

<p>I've already tried to replace the entire element in the 'data' method, like:</p>

<pre><code>newElement.replace(this.element);
this.element = newElement;
</code></pre>

<p>But this seemed not supported: resulted in undefined errors after calling editor.getData().</p>

<p>I'm using ckeditor v4.5.9</p>

<p>Thanks for your help!</p>