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.
@sanchit36 Hello, are you solving the problem? Can you tell how?
Read full answer below ↓Question
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?
Answers (4)
@sanchit36 Hello, are you solving the problem? Can you tell how?
Use this
const page = editor?.Pages.getSelected();
editor?.Pages.add({
id: (page.get('name') || page.id) + '-copy',
component: page.getMainComponent().clone()
}, { select: true });```
@vlont Thanks!
Thanks for reporting this, @sanchit36. Great question about [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.. The recommended approach with StyleManager is to use the event-driven API. Start here: Check the GrapesJS doc...
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3137
When I select an particular element I'm not getting its styles. This issue happens only with some elements.
Not getting styles of the selected element Here is my code, const model = editor.StyleManager.getModelToStyle(component); let styleObject =...
Issue #3401
Can style manager always generate IDs instead of using already defined element's class ?
When we style an element in the editor, if this element doesn't have neither a class or an id, the style manager generate a new id with the...
Issue #3170
Add class name from traits
Hello, what i am trying to achieve is to have the text component extended by assigning an extra trait named Alignment and deciding through...
Issue #5457
Editor Freeze on loadProjectData 0.21.7
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome 117.0 Reproducible demo link localh...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.