2017-03-29 3 views
0

私はPrestaShopモジュールをやっています。このモジュールは "hookDisplayAdminProductsExtra"というフックに固定されます。PrestaShop、Smartyテンプレートから直接tinymceを使用

ライブラリを使用して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} 

私のモジュール機能は次のとおりです。autoload_rteは "使用" され

$this->context->smarty->assign(
    array(
     'row_list' => $this->getField($id) 
    ) 
); 
return $this->display(__FILE__, 'admin-view.tpl'); 

答えて

3

タブ情報は、PrestaShopのでロードされたときに使用した:

$(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(' '); 
        } 
       }); 
      } 
     }); 
    }); 

}); 

その他のタブは、[情報]タブよりも後で読み込まれます。これを解決するには、必要なフィールドに合わせて初期化する必要があります。その後、使用、例えばクラスmytextarea、別のセレクタを選択して(それが必要なのかわからないが、少なくとも100%が現在のものと混乱する機会はありません):

<script>$(document).ready(function(){tinymce.init({mode : "textareas", editor_selector : "mytextarea", plugins: "textcolor paste code"});})</script> 

これはあなたのTPLにすることができます。 私のテストでは、プラグインのセットアップがなければコンソールログにエラーがあります。しかし、あなたは望む通りに設定を調整することができます。

関連する問題