Issue #4273πŸ’¬ AnsweredOpened April 20, 2022by boomshakar1 reactions

How to trigger the 'Import Template (modal)' on page load

Quick answerby boomshakar❀ 1

@boomshakar please don't convert discussions to issues Noted. Thanks

Read full answer below ↓

Question

Hello, Please i'm in need of the logic on how to the import template modal on initialization of the page... I'm using the newsletter preset plugin

Code SnippetTEXT
What i'm trying to achieve?: Make the user upload their code once the page has been loaded.
Below are the logics I've tried,

`
editor.on('load',(model, argument )=> {

        //open modAL
        const modal = edit.Modal;
        const cmdd = edit.Commands;

        //filter using component name
        if (model.getName() === 'Import template') {  //not working
          //show modal
          modal.open();
        }

        edit.on('modal:', (a, b, c) => {  //not working
          console.log({ a });
          console.log({ b });
          console.log({ c });
        });

        cmdd.run('modal:import-template', (a, b, c) => {  //not working
          console.log({ a });
          console.log({ b });
          console.log({ c });
        });
}`

_Originally posted by @boomshakar in https://github.com/artf/grapesjs/discussions/4272_

Answers (4)

boomshakarβ€’ April 22, 2022

@boomshakar please don't convert discussions to issues

Noted. Thanks

boomshakarβ€’ April 21, 2022
Code SnippetTEXT
Hi @artf,
I was able to get what I want by triggering click() on the button itself, 

`

        const modal = edit.Modal;
        const query = new URLSearchParams(location.search);
        const uploadQuery = query.get('key');
        if (uploadQuery === 'upload-code') {
          const importClick = document.querySelector('.gjs-pn-btn.fa.fa-download');
          importClick.click();
          edit.on('modal', (e) => {
            if (e.open && e.title.textContent === 'Import template') {
              modal.setTitle('<div>Import your Template [inline-html/css]</div>');
            }
          });
        }
`

If there's a better workaround, i'd be glad If you share with me the knowledge.
Thanks.
artfβ€’ April 21, 2022

@boomshakar please don't convert discussions to issues

ClaudeCodeβ€’ May 17, 2026

Thanks for reporting this, @boomshakar.

Great question about How to trigger the 'Import Template (modal)' on page load. The recommended approach with Components is to use the event-driven API.

Start here:

  1. Check the GrapesJS documentation for your specific module
  2. Look for the on() event listener method
  3. 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.

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.