Issue #2302Opened September 30, 2019by Amitkumar855332 reactions

How to get the external plugin CSS, JS and HTML through GrapesJS export feature?

Question

Code SnippetTEXT
I have used an external plugin javascript version of @fullCalendar into the GrapesJS. I am able to render the calendar on the canvas but I am unable to use GrapesJS export feature to get JS, CSS and HTML of the following.

I tried using  
 1) var html = editor.getHtml();
 2) var css = editor.getCss();                    
 3) var js = editor.getJs();
4) editor.on('component:mount', comp => console.log(comp.toHtml()));
 
**Calendar  rendered on Canvas  -**

![Calender1](https://user-images.githubusercontent.com/44636520/65910805-0d356900-e3e9-11e9-95c0-164eb608ee84.png)

**Export  of  GrapesJs Editor -**

![Calender2](https://user-images.githubusercontent.com/44636520/65910804-0d356900-e3e9-11e9-8b92-c18320d58179.png)

Kindly help me!
Thanks in advance ...

Answers (3)

pouyamiralayiOctober 1, 20191 reactions

. But we are unable to show users the calendar on the canvas after drag and drop with render function in MODEL that is why we used OnRender in the VIEW.

Did you try the component type definition i posted for you? it has been tested and it is working:

image

So, is the MODEL alone sufficient to render as well as add HTML to export feature? If yes could you please explain how?

yes. it will render the component in the canvas, and include the final code in final html.

if you need any further help for your specific case, i would appreciate a fiddle. cheers!

Amitkumar85533October 1, 20191 reactions

Thanks a lot, @pouyamiralayi. The code you gave was working. Our code was not able to pick the dom element to render the calendar. Now it is working as expected.

Thanks a lot for helping us out !!!! :-p

pouyamiralayiSeptember 30, 20190 reactions

Hi there! what you are looking for is using js inside components.

just include the required js and css in the canvas scripts and styles section:

canvas: {
            styles: [
                'https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/core/main.css',
                'https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/daygrid/main.css',
            ],
            scripts: [
                'https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/core/main.js',
                'https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/daygrid/main.js',
            ],
        },

after that build your own custom type component:

             model: {
                defaults: {
                    ccid:'',
                    tagName: 'div',
                    resizable:true,
                    script: function(){
                            const id = '{[ ccid ]}'
                            var calendarEl = document.getElementById(id);

                            var calendar = new FullCalendar.Calendar(calendarEl, {
                                plugins: [ 'dayGrid' ]
                            });
                            calendar.render();
                    }
                },
            },
            view:{
                init(){
                    this.model.set('ccid',this.model.ccid)
                }
            }
        

then on code preview you will see the result script:

image

cheers!

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

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.