我想将自定义变量添加到Magento的WYSIWYG编辑器(TinyMCE)的“插入变量”弹出窗口
搜索互联网但找不到任何解决方案,这可能吗?任何人?
答案 0 :(得分:1)
您可以在Magento后端添加自定义变量:
System -> Custom Variable -> Add New Variable
您可以在此处添加HTML或纯文本变量。
变量代码是标识符。 变量名称将显示的内容。
要以编程方式添加自定义变量,请参阅此博客:
http://inchoo.net/ecommerce/magento/injecting-variables-into-a-magento-cms-static-block/
答案 1 :(得分:1)
请按照以下说明。
在自定义模块表单中添加字段 应用\代码\本地\命名空间\模块\块\ Adminhtml \模板\电子邮件\编辑\标签\ form.php的
$editor = Mage::getSingleton('namespace/wysiwyg_config')->getConfig(array('tab_id' => $this->getTabId()));
$fieldset->addField('body', 'editor', array(
'name' => 'body',
'label' => Mage::helper('module')->__('Body'),
'title' => Mage::helper('module')->__('Body'),
'style' => 'width:700px; height:500px;',
'config' => $editor,
'wysiwyg' => true,
'required' => true,
));
应用\代码\本地\命名空间\模块\模型\所见即所得\ CONFIG.PHP
<?php
class Namespace_Module_Model_Wysiwyg_Config extends Mage_Cms_Model_Wysiwyg_Config
{
/**
*
* @param Varien_Object
* @return Varien_Object
*/
public function getConfig($data = array())
{
$config = parent::getConfig($data);
$newOptiones = Mage::getSingleton('namespace/variables_options')->getWysiwygPluginSettings($config);
if (isset($newOptiones['plugins'][1]) && is_array($newOptiones['plugins'][1])) {
$config->setData('plugins', array($newOptiones['plugins'][1]));
}
$config->setData('files_browser_window_url', Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/cms_wysiwyg_images/index/'));
$config->setData('directives_url', Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/cms_wysiwyg/directive'));
$config->setData('directives_url_quoted', preg_quote($config->getData('directives_url')));
$config->setData('widget_window_url', Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/widget/index'));
$config->setData('add_variables', true);
return $config;
}
}
应用\代码\本地\命名空间\模块\ Adminhtml \ VariableController.php
<?php
class Namespace_Module_Adminhtml_VariableController extends Mage_Adminhtml_Controller_Action
{
/**
* WYSIWYG Plugin Action
*
*/
public function wysiwygPluginAction()
{
$customVariables = Mage::getModel('namespace/variables_process')->getVariablesOptionArray(true);
$this->getResponse()->setBody(Zend_Json::encode($customVariables));
}
}
应用\代码\本地\命名空间\模块\模型\变量\ Process.php
<?php
class Namespace_Module_Model_Variables_Process extends Mage_Core_Model_Variable
{
public function getVariablesOptionArray($withGroup = false)
{
$collection = $this->getCollection();/*Custom Module Collection*/
$variables = array();
foreach ($collection->toOptionArray() as $variable) {
$variables[] = array(
'value' => '{{customVar code=' . $variable['value'] . '}}',
'label' => Mage::helper('core')->__('%s', $variable['label'])
);
}
if ($withGroup && $variables) {
$variables = array(
'label' => Mage::helper('core')->__('Custom Variables'),
'value' => $variables
);
}
$allVars = array(
$variables
);
return $allVars;
}
}