mirror of https://github.com/artf/grapesjs.git
nocodeframeworkdrag-and-dropsite-buildersite-generatortemplate-builderui-builderweb-builderweb-builder-frameworkwebsite-builderno-codepage-builder
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3.4 KiB
3.4 KiB
Pages
You can customize the initial state of the module from the editor initialization
const editor = grapesjs.init({
....
pageManager: {
pages: [
{
id: 'page-id',
styles: `.my-class { color: red }`, // or a JSON of styles
component: '<div class="my-class">My element</div>', // or a JSON of components
}
]
},
})
Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
const pageManager = editor.Pages;
Available Events
page:add- Added new page. The page is passed as an argument to the callbackpage:remove- Page removed. The page is passed as an argument to the callbackpage:select- New page selected. The newly selected page and the previous one, are passed as arguments to the callbackpage:update- Page updated. The updated page and the object containing changes are passed as arguments to the callbackpage- Catch-all event for all the events mentioned above. An object containing all the available data about the triggered event is passed as an argument to the callback
Methods
add
Add new page
Parameters
Examples
const newPage = pageManager.add({
id: 'new-page-id', // without an explicit ID, a random one will be created
styles: `.my-class { color: red }`, // or a JSON of styles
component: '<div class="my-class">My element</div>', // or a JSON of components
});
Returns Page
remove
Remove page
Parameters
Examples
const removedPage = pageManager.remove('page-id');
// or by passing the page
const somePage = pageManager.get('page-id');
pageManager.remove(somePage);
Returns Page
get
Get page by id
Parameters
idString Page id
Examples
const somePage = pageManager.get('page-id');
Returns Page
getMain
Get main page (the first one available)
Examples
const mainPage = pageManager.getMain();
Returns Page
getAll
Get all pages
Examples
const arrayOfPages = pageManager.getAll();
select
Change the selected page. This will switch the page rendered in canvas
Parameters
Examples
pageManager.select('page-id');
// or by passing the page
const somePage = pageManager.get('page-id');
pageManager.select(somePage);
Returns this
getSelected
Get the selected page
Examples
const selectedPage = pageManager.getSelected();
Returns Page