Custom html elements
Question
Is it possible, and if so how to do it, to use a custom html element e.g.
<body> <my-custom-tag/> </body>Which will render specific html for the preview window, but the source will output the custom tag?
Thanks, Paul
Answers (3)
Yeah you can use different tag names in your custom component
const dc = editor.DomComponents;
const defaultType = dc.getType('default');
dc.addType('my-custom-type', {
model: defaultType.model.extend({
tagName: `custom-tag`
}, {
isComponent(el) {
if(el.tagName == 'CUSTOM-TAG')
return {type: 'my-custom-type'}
},
}),
view: defaultType.view.extend({
tagName: 'div' //<-- in canvas div will be used
})
});
Thanks @artf, that points me in the right direction.
If I want the anything that needs to be editable in the block to appear in the custom tag code, how would I achieve that?
You mean something like this?
editor.BlockManager.add('custom-block', {
label: 'Custom Block'
content: '<custom-tag>...</custom-tag>',
})
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1746
[FEATURE REQUEST] Don't Strip off html , head and body tags from imported html
Hi Team, We have noticed grapesjs has customised the actual template uploaded, by stripping off the html, head and body tags and adds new s...
Issue #1877
[FEATURE REQUEST] Custom styles that add/remove custom classes?
Currently, all the style manager values that you change for an element simply update a <style> tag inline in the HTML. Is it possible to ch...
Issue #786
How to get the next and previous models/elements of selected element
I am cloning an element. I want to get the next element or previous element. By this I mean to say that How can I get the model or How shou...
Issue #1198
QUESTIONS : Find element in Model
I have custom component and it render below html, I want to update value of h4 tilte and other element on trait changed, but not sure how c...
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.