Issue #1372💬 AnsweredOpened August 21, 2018by mm5804860 reactions

Change block on export

快速解答by artf

I'd make a custom component to handle such a case.

Read full answer below ↓

Question

i want change my view but not on export

for sample i added this code


blockManager.add('products', {
  label: 'products',
  content: '
  <ul>
    {% for product in products %}
      <li>{{ product.name }}</li>
    {% endfor %}
  </ul>
',
});

and now i want show this code on view


blockManager.add('products', {
  label: 'products',
  content: '
  <ul>
      <li>car</li> <!-- fake data for show on view -->
      <li>train</li> <!-- fake data for show on view -->
  </ul>
',
});

how can i take this action ?

Answers (2)

artfAugust 24, 2018

I'd make a custom component to handle such a case.

domc.addType('data-list', {
	model: ...
		defaults: () => ({
			...
			list: []
		}),

	view: ...
		render() {
			... 
			const list = this.model.get('list');
			const content = this.el.innerHTML;
			// interpolate / use some template engine
		}
});

blockManager.add('products', {
  label: 'products',
  content: `
  <ul gjs-data-type="data-list" gjs-data-list="[{...}, {...}]">
    {% for product in products %}
      <li>{{ product.name }}</li>
    {% endfor %}
  </ul>
`,
});
lock[bot]September 17, 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.