4

MagentoのCMSページ用のWYSIWYGエディターには、Magentoウィジェットをエディターに追加するためのツールがあります。WYSIWYGでも、製品とカテゴリの説明でこれを利用できるようにしたいと思います。

現在、エディターがロードされている場所を見つけるのに苦労しています。誰かが私に何をしなければならないかを教えてもらえますか、少なくとも私を正しい方向に向けることができますか?

前もって感謝します。

ここに画像の説明を入力してください

4

4 に答える 4

7

@David Mannerの回答に従って有効add_widgetsadd_variablesしてクラスに入れると、WYSIWYGエディターでこれらが確実に有効になり、正しく機能する一方で、(適切なものではなく)フロントエンドで生のウィジェット/変数コードのみがレンダリングされることがわかります。Mage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg_Contentマークアップ)。

次の方法で修正できます:-

案内する/app/design/frontend/package/theme/template/catalog/category/view.phtml

探す<?php if($_description=$this->getCurrentCategory()->getDescription()): ?>

この行の下に以下を追加します:-

<?php 
    $helper = Mage::helper('cms'); 
    $processor = $helper->getPageTemplateProcessor(); 
    $_description = $processor->filter($_description); 
?>

これにより、フロントエンドで正しくレンダリングされます。

于 2014-03-03T12:44:53.460 に答える
4

クラスMage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg_Contentの下には、構成配列「add_widgets」と「add_variables」に2つのフラグがあります。これらは両方ともデフォルトでfalseに設定されています。

これらをtrueに設定すると、イベントcms_wysiwyg_config_prepareのMage_Widget_Model_Observerクラス関数prepareWidgetsPluginConfigでキャッチされます。

Mage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg_Contentをニーズに合わせて書き直すことをお勧めしますが、add_widgetsとadd_variablesをtrueに設定すると、カテゴリと製品の両方で機能するはずです。

于 2013-02-12T16:10:32.477 に答える
1

すべての答えを読んだ後、私はエレガントな解決策を見つけました。このソリューションは、1つのBlockクラスのみを書き換え、テンプレートファイルを変更しません。

  1. Mage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg_Contentを書き換えます

    <config> ... <global> <blocks> ... <adminhtml> <rewrite> <catalog_helper_form_wysiwyg_content>Agere_Wysiwyg_Block_Widget_Anywhere</catalog_helper_form_wysiwyg_content> </rewrite> </adminhtml> </blocks> ... </global> </config>

  2. 構成配列'add_widgets'および'add_variables'の2つのフラグのみをtrueに変更します

    class Agere_Wysiwyg_Block_Widget_Anywhere extends Mage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg_Content {
        protected function _prepareForm() {
            //return parent::_prepareForm();
            $form = new Varien_Data_Form(array('id' => 'wysiwyg_edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
    
            $config['document_base_url']     = $this->getData('store_media_url');
            $config['store_id']              = $this->getData('store_id');
            $config['add_variables']         = true;
            $config['add_widgets']           = true;
            $config['add_directives']        = true;
            $config['use_container']         = true;
            $config['container_class']       = 'hor-scroll';
    
            $form->addField($this->getData('editor_element_id'), 'editor', array(
                'name'      => 'content',
                'style'     => 'width:725px;height:460px',
                'required'  => true,
                'force_load' => true,
                'config'    => Mage::getSingleton('cms/wysiwyg_config')->getConfig($config)
            ));
            $this->setForm($form);
    
            return $this;
        }
    }
    
  3. カテゴリまたは製品のコンテンツを処理するハンドラーを作成します

    class Agere_Wysiwyg_Helper_Filter extends Mage_Core_Helper_Abstract {
        public function categoryAttribute($mainHelper, $result, $params) {
            return $this->process($result);
        }
    
        public function productAttribute($mainHelper, $result, $params) {
            return $this->process($result);
        }
    
        public function process($result) {
            /** @var Mage_Cms_Helper_Data $helperCms */
            $helperCms = Mage::helper('cms');
            $processor = $helperCms->getPageTemplateProcessor();
    
            return $processor->filter($result);
        }
    }
    
  4. 最後に、outwysiwygのハンドラーを追加するオブザーバーを作成します

    class Agere_Wysiwyg_Model_Observer extends Varien_Event_Observer {
        public function addWysiwygHandler(Varien_Event_Observer $observer) {
            /** @var Mage_Catalog_Helper_Output $_helperOutput */
            /** @var Agere_Wysiwyg_Helper_Filter $_helperFilter */
            $_helperOutput = Mage::helper('catalog/output');
            $_helperFilter = Mage::helper('agere_wysiwyg/filter');
            $_helperOutput->addHandler('categoryAttribute', $_helperFilter);
            $_helperOutput->addHandler('productAttribute', $_helperFilter);
        }
    }
    

コードの完全なスナップはリンクhttps://github.com/popovsergiy/magento-wysiwygで参照してください

于 2015-10-06T19:58:07.487 に答える
0

より良い方法は、同じイベントをリッスンする新しいオブザーバーを作成し、Mage_Widgetに依存するモジュールを作成することです。次に、オブザーバーはMage_Widgetの後に実行されます

于 2013-02-14T14:04:22.610 に答える