【问题标题】:PrestaShop, use tinymce directly from Smarty templatePrestaShop,直接从 Smarty 模板使用 tinymce
【发布时间】:2017-03-29 08:27:06
【问题描述】:

我正在做一个 PrestaShop 模块。该模块将锚定到名为“hookDisplayAdminProductsExtra”的钩子上。

我需要通过库使用 TEXTAREA 字段 tinymce,您可以通过直接从 Smarty 创建 textarea 而不是作为控制器来实现吗?也许使用 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');

【问题讨论】:

    标签: php tinymce smarty prestashop prestashop-1.6


    【解决方案1】:

    当 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 设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-25
      • 1970-01-01
      • 2012-06-19
      • 1970-01-01
      • 2019-01-09
      • 1970-01-01
      • 2017-06-11
      相关资源
      最近更新 更多