Issue #424Opened October 16, 2017by aryeharmon0 reactions

custom competent <template> missing inner html when creating a block with it

Question

you gave me a fix in #244 but this is no longer working

Answers (3)

artfOctober 16, 20170 reactions

Hey @aryeharmon I just used this in the demo (try it by yourself in console)

var domc = editor.DomComponents;
var defaultModel = domc.getType('default').model;
var defaultView = domc.getType('default').view;
domc.addType('template', {
  model: defaultModel.extend({}, {
    isComponent: function(el) {
      if (el.tagName == 'TEMPLATE') {
      console.log(el, el.innerHTML);
        // as template.children will return an empty array the traverser
        // will skip all nodes, therefore attach them as a string (they 
        // will be processed later)
        return {type: 'template', components: el.innerHTML}
      }
    }
  }),
  view: defaultView.extend({
    // '<template>' can't be shown so in canvas use another tag
    tagName: 'div'
  }),
});

and importing <div><template><div>SOME TEXT</div></template></div> works just as expected.

aryeharmonOctober 18, 20170 reactions

OK so i see what the issue is, apparently when i add:

var domc = editor.DomComponents;
var defaultModel = domc.getType('default').model;
var defaultView = domc.getType('default').view;
domc.addType('template', {
  model: defaultModel.extend({}, {
    isComponent: function(el) {
      if (el.tagName == 'TEMPLATE') {
      console.log(el, el.innerHTML);
        // as template.children will return an empty array the traverser
        // will skip all nodes, therefore attach them as a string (they 
        // will be processed later)
        return {type: 'template', components: el.innerHTML}
      }
    }
  }),
  view: defaultView.extend({
    // '<template>' can't be shown so in canvas use another tag
    tagName: 'div'
  }),
});

to html the existing elements on page do not take effect. only newly added dom elements. for example i already have a template tag on page when load, i will not get the properties. but if i add the template after it will work.

aryeharmonOctober 18, 20170 reactions

btw, the editor.render(); is after the register of domc.addType

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.