grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

[QUESTION]: I'm trying to duplicate the page, but the styles are not geting applied due to the Ids, changes to -2,-3 at the end.

Open sanchit36 opened this issue 5 years ago • 4 comments

  const duplicatePage = (editor) => {
    let components = editor.getHtml();
    let css = editor.getCss();
    let newPage = editor.Pages.add({
      styles: css,
      component: components,
    });
    editor.Pages.select(newPage);
  };

This is what my function looks like. I am trying duplicate the page, the HTML part is fine but as css is applied through ids, when a new page render the ids changes with -2 in end of them. Is there any to prevent it, or any other way of doing this?

sanchit36 avatar Jul 17 '21 02:07 sanchit36

@sanchit36 Hello, are you solving the problem? Can you tell how?

OrigoVl avatar Feb 07 '23 01:02 OrigoVl

I also need to know, if this has been resolved and how.

leonardolima99 avatar Feb 16 '23 19:02 leonardolima99

Use this

const page = editor?.Pages.getSelected();

editor?.Pages.add({
    id: (page.get('name') || page.id) + '-copy',
    component: page.getMainComponent().clone()
}, { select: true });```

vlont avatar Feb 16 '23 20:02 vlont

@vlont Thanks!

leonardolima99 avatar Feb 17 '23 14:02 leonardolima99