GrapesJS / preset-webpage

GrapesJS Plugin Webpage Preset
http://grapesjs.com/demo.html
BSD 3-Clause "New" or "Revised" License
335 stars 291 forks source link

[QUESTIONS] How to add Categories #46

Closed Aiyush-G closed 2 years ago

Aiyush-G commented 4 years ago

@artf How should I add categories (the drop downs on the side) to the template. I would like to add some custom blocks to a category, however, I am not clear on how to do this and what code I should put in what categories.

Any help would be much appreciated.

Kind Regards Aiyush

RJCAM commented 4 years ago

@Aiyush-G you can use the property "category" when creating a custom block, example:

editor.BlockManager.add('custom_block', {
    label: 'Custom Block',
    category: 'Custom Category',
    attributes: {
        class: 'gjs-fonts gjs-f-b1',
    },
    content: `<div class="custom"></div>`,
});
sagar7993 commented 1 year ago

This creates a new category which is rendered below all the existing categories. Is there a way to render this category at the top above all the existing categories?

leo-budgetsimple commented 11 months ago

This creates a new category which is rendered below all the existing categories. Is there a way to render this category at the top above all the existing categories?

You can set 'order' for categories, like this:

editor.BlockManager.add('custom_block', {
    label: 'Custom Block',
    category: {
      id: 'custom-category',
      label: 'Custom Category',
      order: 0,
    },
    attributes: {
        class: 'gjs-fonts gjs-f-b1',
    },
    content: `<div class="custom"></div>`,
});