I am trying to add helper function to cms block or page but it didn't parse like other directives.can anyone help to resolve this issue.or how make helper directive to work in cms block or cms page.
<?php
class Mage_Customer_Helper_Data extends Mage_Core_Helper_Abstract
{
public function useInWysiwygEditor{
/* logic should be anything */
return $this->getUrl('contact')
}
}
now in cms editor i want to use like {{helper useInWysiwygEditor()}}
Thanks
-
can you show the code ?MeenakshiSundaram R– MeenakshiSundaram R2015年07月02日 08:36:11 +00:00Commented Jul 2, 2015 at 8:36
-
please explain questionAshvin Monpara– Ashvin Monpara2015年07月02日 08:56:59 +00:00Commented Jul 2, 2015 at 8:56
1 Answer 1
I have created one custom module for this
and we have specified the our filter to magento by adding the following code in config.xml page
<global>
<cms>
<page>
<tempate_filter>[Namespace]_[Module]_Model_Template_Filter</tempate_filter>
</page>
<block>
<tempate_filter>[Namespace]_[Module]_Model_Template_Filter</tempate_filter>
</block>
</cms>
<global>
Then create the file [Namespace]/[Module]/Model/Template/Filter.php
class [Namespace]_[Module]_Model_Template_Filter extends Mage_Widget_Model_Template_Filter
{
public function helperDirective($construction)
{
$params = $this->_getIncludeParameters($construction[2]);
$allowedParams = array('module', 'method', 'params');
if(empty($params) || !count(array_intersect($allowedParams, array_keys($params)))){
return $construction[0];
}
if((isset($params['module']) && !empty($params['module'])) && (isset($params['module']) && !empty($params['module']))){
try{
$helper = Mage::helper($params['module']);
if(is_callable(array($helper, $params['method']), true, $params['method'])){
$arg = array();
$method = $params['method'];
if(isset($params['params']) && !empty($params['params'])){
$arg = explode(',',$params['params']);
}
return call_user_func_array(array($helper, $method), $arg);
}
} catch (Exception $e){
return $construction[0];
}
}
return $construction[0];
}
}
Note: here the function name is helperDirective. if you that to {{custom }} so the function name will customDirective (i.e,{{youname}}Directive)
Then I have use 3 parameters for this.
So you can call your helper function by following way
{{helper module="yourmodule" method="yourfunction" params="arg1,arg2,..etc"}}
here
module => 'module helper name'
method => 'function name'
params => 'parameters of the function'
I have created this module by following this tutorial
-
Its working perfectly mate.Thanks. But i confused about
tempate_filteri thought it should betemplate_filter:)Zahirabbas– Zahirabbas2018年11月15日 07:05:36 +00:00Commented Nov 15, 2018 at 7:05
Explore related questions
See similar questions with these tags.