Add external script in script while creating new component
@HarshOB https://github.com/artf/grapesjs/wiki/Components-&-JS#template-related
Read full answer below ↓Question
Hello @artf
How can I pass external script link while creating a component? like this way,
bm.add('test-block2', { label: 'Test block2', attributes: {class: 'fa fa-text'}, content: { script: '<script src="https://cdn.ckeditor.com/4.6.2/full/ckeditor.js"></script>CKEDITOR.replace( \'editor1\' )', content: '<textarea name="editor1"></textarea>' } });
Right now it shows error like unexpected token '<'
Answers (3)
Move the script tag to import CKEditor on the html page and just call the script inside the block.
javascript somehow not allowing script end tag ("</script>") with in string. So just change the code to be like:
script: '<script>alert("Hi");<' + '/script>'
Related Questions and Answers
Continue research with similar issue discussions.
Issue #634
How can I pass content with script?
I made custom component like this way and used script as well then script is working fine but I am not able to select component. Is there a...
Issue #1817
Change HTML content while block is render in editor
Hello @artf I have one block into block manager like As per above script inside the block, i want to add dynamic HTML content while this bl...
Issue #792
Script property using function don't work with blocks
In Components & JS docs there's this example: This works perfectly. But I couldn't use a function instead of a string in script, as is said...
Issue #1545
[Question] How I Get ID From Block?
Hi, i have my block and I get print in Div id results from my javascript class component... How i get ID from my block ??? editor.BlockMana...
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 →Related tutorials
In-depth guides on the same topic.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.