Custom competent <template> missing inner html when creating a block with it
Hey @aryeharmon I just used this in the demo (try it by yourself in console) and importing <div><template><div>SOME TEXT</div></template></div> works just as expected.
Read full answer below ↓Question
you gave me a fix in #244 but this is no longer working
Answers (3)
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.
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.
btw, the editor.render(); is after the register of domc.addType
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1369
[BUG] Class of a block doesn't always show in the classes section
Hello everyone, I have added many custom blocks and gave the same css class to all the images in those blocks. Let's call it for now 'image...
Issue #1696
Traits appear first time when draged custom component
Hi artf , i have created custom component and add traits for it , when dragging this component to editor and select it the setting traits w...
Issue #1109
[QUESTION] Column blocks not droppable in canvas
Morning @artf :) I'm experiencing an similar problem to this issue. I can't drop any block (text, image, etc.) inside the column block from...
Issue #1618
Child components are not tracked in models ??
Hi, I'm facing as strange issue and I need your help. when I move components inside blocks, at the view model the changes successfully appl...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.