Issue #1792Opened February 14, 2019by abozhinov0 reactions

[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)

abozhinovFebruary 15, 20190 reactions

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',

Code SnippetTEXT
'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'
						};
					}
				}
			}
		)
	});
lock[bot]February 16, 20200 reactions

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.

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.