Issue #565Opened November 23, 2017by paulroberttaylor-zz0 reactions

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)

artfNovember 23, 20170 reactions

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
  })
});
paulroberttaylor-zzNovember 24, 20170 reactions

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?

artfNovember 24, 20170 reactions

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.

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.