Issue #2303Opened October 2, 2019by megarg2 reactions

Updating toHTML of a new custom component

Question

I would like to change how the toHTML output. I would like to modify the existing html output.

I tried the "toHTML" property of component

  • it allows to return a new html element
  • but it does not allow to get existing html and then update it and return it

I tried calling toHTML inside toHTML to get access to original component html but as expected it went in an infinite loop.

Is there a way to get access to existing toHTML so that I can modify it and then return as new "toHTML:. Editor or export will use the new output.

Answers (3)

megargOctober 3, 20191 reactions
Code SnippetTEXT
i solved this by doing below
`
toHTML: function () {
        let el = `<script>  console.log("add script here") </script>`;
        el = defaultType.model.prototype.toHTML.apply(this) + el;
        return el;
      },
`

Thanks a lot for your support
scott-coatesNovember 12, 20191 reactions

To get defaultType run this: var defaultType = editor.DomComponents.getType('default');

And this works too:

var prototype = Object.getPrototypeOf(this);
var el = prototype.__proto__.toHTML.call(this);
return el;
pouyamiralayiOctober 2, 20190 reactions

Hi! did you try using component.view.el inside your toHTML? it will give you access to the current DOM. cheers!

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.