[Question] Exclude some components from final html (Multi-level)
Question
Hi, I have a question about how to exclude HTML from editor->getHtml().
My structure is something like that.
Parent
- Child -- Child --- Child
I want to save the HTML from the last Child. How to do that?
Answers (2)
This is my solution: domc.addType('layout', { model: defaultModel.extend( { defaults: Object.assign( {}, defaultModel.prototype.defaults, { removable: false, draggable: false, droppable: false, badgable: false, stylable: false, highlightable: false, copyable: false, resizable: false, editable: false, layerable: false, selectable: false, hoverable: false, propagate: [ 'removable', 'draggable', 'droppable', 'badgable', 'stylable', 'highlightable',
'copyable',
'resizable',
'editable',
'layerable',
'selectable',
'hoverable'
],
jsUrl: config.jsUrl,
script: function () {
AssetManager.loadJS('{[ jsUrl ]}');
}
}
),
toHTML: function() {
function getHtml(components) {
let i;
for (i=0; i < components.length; i++)
{
let component = components[i];
if (component.attributes.tagName !== 'div')
continue;
if (component.attributes.attributes.hasOwnProperty('data-page-editor-content'))
{
return component;
}
else if (component.attributes.components.models.length > 0)
{
return getHtml(component.attributes.components.models);
}
}
}
let editorContent = getHtml(this.attributes.components.models);
editorContent.script = '';
return defaultType.model.prototype.toHTML.apply(editorContent);
}
},
{
isComponent(el) {
if(el.id === 'js-wrapper') {
return {
type: 'layout'
};
}
}
}
),
view: defaultType.view,
});
domc.addType('editor-content', {
model: defaultModel.extend(
{
defaults: Object.assign(
{},
defaultModel.prototype.defaults,
{
removable: true,
draggable: true,
droppable: true,
badgable: true,
stylable: true,
highlightable: true,
copyable: true,
resizable: true,
editable: true,
layerable: true,
selectable: true,
hoverable: true,
propagate: [
'removable',
'draggable',
'droppable',
'badgable',
'stylable',
'highlightable',
'copyable',
'resizable',
'editable',
'layerable',
'selectable',
'hoverable'
],
}
)
},
{
isComponent(el) {
if(el.nodeType === Node.ELEMENT_NODE && el.hasAttribute('data-page-editor-content')) {
return {
type: 'editor-content'
};
}
}
}
)
});This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #363
[QUESTION] How to get child object ?
Hi @artf i want to ask about get some child from current model, let's say in that source code, can i get child object like get parent objec...
Issue #1889
How to append a child component at required position/index
For example, I have a parent component and this parent component has 4 child components. Here with trait functionality, I want to move the...
Issue #1875
[QUESTION] ID changes when importing html or passing html in components prop in config.
Hi, I built a component and block that I can drag and drop in the canvas. My issue is that some styles rely on the ID. I know this might no...
Issue #1787
[Question] Change HTML of Panel buttons from span to button
I have created some Panels and would like to change the element of panel buttons from span to button as its more appropriate and looks bett...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.