[英]PrestaShop, use tinymce directly from Smarty template
我正在做一个PrestaShop模块。 该模块将固定在名为“ hookDisplayAdminProductsExtra”的钩子上。
我需要使用库来使用TEXTAREA字段tinymce,您可以通过直接从Smarty创建文本区域而不是作为控制器来做到这一点? 也许使用jQuery函数或向该字段添加一个类?
我在tpl文件中的代码是:
{foreach $row_list as $row}
<textarea id="description_1" name="description_1" class="autoload_rte" aria-hidden="true">
{$row['desc']}
</textarea>
{/foreach}
我的模块功能是:
$this->context->smarty->assign(
array(
'row_list' => $this->getField($id)
)
);
return $this->display(__FILE__, 'admin-view.tpl');
当Prestashop使用以下选项加载“信息”选项卡时,将“使用” autoload_rte:
$(document).ready(function(){
// Execute when tab Informations has finished loading
tabs_manager.onLoad('Informations', function(){
tinySetup({
editor_selector :"autoload_rte",
setup : function(ed) {
ed.on('init', function(ed)
{
if (typeof ProductMultishop.load_tinymce[ed.target.id] != 'undefined')
{
if (typeof ProductMultishop.load_tinymce[ed.target.id])
tinyMCE.get(ed.target.id).hide();
else
tinyMCE.get(ed.target.id).show();
}
});
ed.on('keydown', function(ed, e) {
tinyMCE.triggerSave();
textarea = $('#'+tinymce.activeEditor.id);
var max = textarea.parent('div').find('span.counter').data('max');
if (max != 'none')
{
count = tinyMCE.activeEditor.getBody().textContent.length;
rest = max - count;
if (rest < 0)
textarea.parent('div').find('span.counter').html('<span style="color:red;">Maximum '+ max +' characters : '+rest+'</span>');
else
textarea.parent('div').find('span.counter').html(' ');
}
});
}
});
});
});
除此之外,其他选项卡也比信息选项卡晚加载。 要解决此问题,您需要为所需的字段初始化tinymce。 选择另一个选择器(不确定是否需要它,但是至少没有100%的机会与当前选择器混淆),例如类mytextarea,然后使用:
<script>$(document).ready(function(){tinymce.init({mode : "textareas", editor_selector : "mytextarea", plugins: "textcolor paste code"});})</script>
这可以在您的tpl中。 在我的测试中,如果没有插件设置,则控制台日志中会出现错误。 但是您可以根据需要调整tinymce设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.