HTML head tags not added to the dom
Thanks for reporting this, @throne1986. Great question about HTML head tags not added to the dom. The recommended approach with ProseMirror is to use the event-driven API. Start here: Check the GrapesJS documentation for your specific module Look for the on() event listener method Most operations can be achieved by li...
Read full answer below βQuestion
I am using [grapesjs library][1] for building web pages, I have added a custom block as per docs [here][1] when I drag the block to canvas HTML data is added but `<head></head>` tag is empty,
Here is my code
function tempOnePlugin(editor) {
editor.BlockManager.add('my-first-block', {
label: '<i class="fa fa-clone"></i>',
content: `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Vmmerce Template</title>
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<meta name="description" content="Start learning various skills in demand through our educational institution.">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css" rel="stylesheet">
</head>
<body>
</body>
<div class="demo">How are you ? </div>
</html>`,
css: null
});
}
const editor = grapesjs.init({
container: '#gjs',
fromElement: true,
height: '100%',
storageManager: false,
plugins: ['gjs-blocks-basic', 'tempOnePlugin'],
dragMode: 'absolute'
});
[Live demo:][2] add a block to canvas
[![enter image description here][3]][3]
Inspect the added block, u will see the inserted HTML its head is empty
[![enter image description here][4]][4]
Why inserted HTML block its head is empty?
[1]: https://grapesjs.com/docs/modules/Blocks.html#custom-render
[2]: https://jsfiddle.net/d4702yoh/
[3]: https://i.stack.imgur.com/x14OZ.png
[4]: https://i.stack.imgur.com/nUYOt.pngAnswers (1)
Thanks for reporting this, @throne1986.
Great question about HTML head tags not added to the dom. The recommended approach with ProseMirror is to use the event-driven API.
Start here:
- Check the GrapesJS documentation for your specific module
- Look for the
on()event listener method - Most operations can be achieved by listening to editor and component events
Common patterns:
// Listen for changes
editor.on('change', () => console.log('something changed'));
// Component lifecycle
editor.on('component:mount', (c) => console.log('component ready', c));
editor.on('component:update', (c) => console.log('component updated', c));
If you're still stuck:
- Share a minimal CodeSandbox reproduction
- Include what you've already tried
- Mention your GrapesJS version
- The community is here to help!
Related Questions and Answers
Continue research with similar issue discussions.
Issue #5607
Cannot expand previously empty layers
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v120.0.6099.199 Reproducible demo l...
Issue #3269
Translating html string
Great library! It meets all the requirements but one: website text translation. I've searched high and low through the issue queue and docs...
Issue #3238
[Question]: How to load external javascript,i tried all methods,Useless
I write html strings as blocks, and need to introduce a lot of external scripts and styles, but I tried all the methods, when I drag the bl...
Issue #6663
Symbols break when loading pages progressively (instances lose __symbol link)
Here is a video showing the bug: https://github.com/user-attachments/assets/0fdc76ed-cee5-4481-98b1-cbbf52572b31 GrapesJS version [x] I con...
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.