【发布时间】:2014-06-11 13:01:33
【问题描述】:
TinyMce 与 Twig 结合使用时遇到问题, 我正在尝试将带有 twig 标签的 html 粘贴到 tinyMce 中。 (使用原始 html)
这就是我想要的结果:
<table>
<thead>
<tr>
<th></th>
{% for period in report.periods %}
<th>
{% set per = "last_" ~ period %}
{{ per | trans({}, "admin") }}
</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for category in report.categories %}
<tr>
<td>
<b>{{ category | trans({}, "admin") }}</b>
</td>
{% for period in report.periods %}
<td>
{{ data[category][period] }}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
这就是我将它粘贴到 tinyMce 并验证我的 HTML 时的样子
<p>{% for period in report.periods %} {% endfor %} {% for category in report.categories %} {% for period in report.periods %} {% endfor %} {% endfor %}</p>
<table>
<thead>
<tr>
<th></th><th>{% set per = "last_" ~ period %} {{ per | trans({}, "admin") }} </th>
</tr>
</thead>
<tbody>
<tr>
<td><b>{{ category | trans({}, "admin") }}</b></td>
<td>{{ data[category][period] }}</td>
</tr>
</tbody>
</table>
如您所见,tinyMce 将我的 twig 标签移到表格之外,并破坏了我想做的所有逻辑。
我已经直接在官方网站上尝试了 tinyMce (cleanup : false) 的多个配置以及多个版本 (3.x、4.x)。
但它也不起作用
感谢您的帮助。
【问题讨论】:
-
如何在 TinyMCE 中粘贴 twig html 内容?你用
raw了吗? -
我在所见即所得编辑器中用 html 代码编写 jinja 代码时遇到了同样的问题,我试图用 javascript 中的正则表达式来克服这个问题,这真的是很难的代码。