Issue #1556πŸ’¬ AnsweredOpened November 1, 2018by thanhpd560 reactions

Add new block to block manager: predefined content and editor content is different

Quick answerby artf

If you drop a not valid HTML structure it will be rearranged by the browser, you can't prevent it

Read full answer below ↓

Question

I try to use template engine with grapesjs. Add new block by this:

bm.add('promotion-lines', {
    label: 'Promotion Lines',
    category: c.labelCategory,
    attributes: {class: 'fa fa-list-ol'},
    content: `<ul>
  <table style="box-sizing: border-box; height: 150px; margin: 0 auto 0 auto; padding: 0 0 0 0; width: 100%;">
    <tbody style="box-sizing: border-box;"><tr style="box-sizing: border-box;">
     {% for order_line in order.order_lines %}
     <td style="box-sizing: border-box; padding: 0; margin: 0; vertical-align: top;" valign="top"/>
      {% endfor %}
    </tr>
    </tbody>
  </table>
</ul>`,
  });

Drag new block to editor then the content of editor is different from above: (the {% for order_line in order.order_lines %} is moved up)

<ul style="box-sizing: border-box;">
  {% for order_line in order.order_lines %}
  <table id="imf58" style="box-sizing: border-box; height: 150px; margin: 0 auto 0 auto; padding: 0 0 0 0; width: 100%;" width="100%" height="150">
    <tbody id="isbik" style="box-sizing: border-box;">
      <tr id="ikbcn" style="box-sizing: border-box;">
        <td valign="top" id="ipg0l" style="box-sizing: border-box; padding: 0; margin: 0; vertical-align: top;">
          {% endfor %}
        </td>
      </tr>
    </tbody>
  </table>
</ul>

How can i prevent this? Thanks.

Answers (2)

artfβ€’ November 3, 2018

If you drop a not valid HTML structure it will be rearranged by the browser, you can't prevent it

lock[bot]β€’ November 3, 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.