Issue #1528💬 AnsweredOpened October 18, 2018by nine-2-five0 reactions

The custom block doesn't execute its script when autoloaded from localStorage

快速解答by nine-2-five

False alarm, sorry. I checked the grapesjs-preset-webpage, and realized I was registering the block but no component. Once I added the component to editor.DomComponents, it started rendering the carousel even when loaded from localStorage.

Read full answer below ↓

Question

代码片段TEXT
I'm using the following code for my custom block, and it works when the block is dropped on the canvas.
But when the block is loaded from localStorage, it only creates a div wrapper and doesn't execute the content.script part of custom block.<br>
I tried simplifying the script property to just alert or console call but it didn't help. No errors in console.

      blockManager.add('a3-owl-carousel', {
        label: 'Owl Carousel',
        content:{
          type: 'slider',
          script: function(){                         
            var _component = this;

            (function($){                
                $.get('http://localhost:8080/content/hr.json', function(data){
                  $.get('http://localhost:8080/content/slider.twig', function(twig_template){
                    var template = Twig.twig({data: twig_template});                    

                    $(_component).html(template.render(data));
                  });      
                }); 
            })(jQuery);
          } 
        }    
      });      `

Answers (2)

nine-2-fiveOctober 18, 2018

False alarm, sorry. I checked the grapesjs-preset-webpage, and realized I was registering the block but no component. Once I added the component to editor.DomComponents, it started rendering the carousel even when loaded from localStorage.

lock[bot]October 18, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

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 →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.