Issue #2670💬 AnsweredOpened March 19, 2020by kohki-shikata1 reactions

Doesn't appear HTML class name of a custom block on editor

快速解答by artf1

Classes should be placed in classes

Read full answer below ↓

Question

I added my block like this below

const editor = grapesjs.init({
// ...
blockManager: {
    appendTo: '#blocks',
    blocks: [
      {
        id: 'main-title',
        label: 'Main title',
        category: 'Titles',
        content: {
          type: 'text',
          tagName: 'p',
          attributes: { class: 'main-title' },
          content: 'This is Main title. To click here to edit this'          
        }
      }
    ]
  },
canvas: {
    styles: [
      'https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css', // reset style of canvas
      '/assets/css/content.css' // 👈This contains the style for .main-title
    ]
  },

Then drag this block and drop to canvas, and show HTML code with export-template command.

<p class="main-title">This is Main title. To click here to edit this
</p>

👆OK, this is what I expected.

BUT, HTML class doesn't appear on the element inside of the editor, so it's not applied style for .main-title.

<img width="793" alt="スクリーンショット 2020-03-20 2 36 53" src="https://user-images.githubusercontent.com/4133263/77097455-2a6ff980-6a54-11ea-9e74-f5af7982b1b4.png"> <img width="706" alt="スクリーンショット 2020-03-20 2 37 45" src="https://user-images.githubusercontent.com/4133263/77097417-1b894700-6a54-11ea-9e90-6d9e9ea0970d.png">

I need to set html class default my custom block. How should I do?

Answers (1)

artfMarch 20, 2020

Classes should be placed in classes

content: {
          type: 'text',
          tagName: 'p',
		  classes: 'main-title',
          content: 'This is Main title. To click here to edit this'          
        }

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...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

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.