我创建了一个扩展,其中包含我的自定义函数。
class AppExtension extends \Twig_Extension { private $_container; public function __construct($container) { $this->_container = $container; } public function getFunctions() { return [ new \Twig_SimpleFunction('autologin', [$this, 'autologin'], ['is_safe' => ['all']]) ]; } public function autologin($customer, $url) { return sprintf(''); } public function getName() { return 'xxx_app_extension'; } }
我已将其添加到services.yml:
xxx_opportunity.twig.helper:
class: 'OpportunityBundle\Twig\AppExtension'
public: false
arguments:
- '@service_container'
tags:
- { name: twig.extension }
当我通过执行“ php bin / console debug:twig”查看ORO是否找到它时,可以看到我的自定义函数出现在列表中。当我尝试使用OROcrm中的电子邮件模板编辑器在电子邮件模板中实现它时,出现以下错误:
The template for xxxx has syntax error: Unknown "autologin" function at line 18.
这已经困扰了我很久了,有人可以解决吗?
更新:
$instance = new \Oro\Bundle\EmailBundle\Provider\EmailRenderer(${($_ = isset($this->services['oro_email $instance->addExtension(${($_ = isset($this->services['oro_ui.twig.html_tag']) ? $this->services['oro_u $instance->addExtension(${($_ = isset($this->services['oro_config.twig.config_extension']) ? $this->ser $instance->addExtension(${($_ = isset($this->services['oro_ui.twig.extension.formatter']) ? $this->serv $instance->addExtension(${($_ = isset($this->services['oro_locale.twig.address']) ? $this->services['or $instance->addExtension(${($_ = isset($this->services['oro_locale.twig.date_time']) ? $this->services[' $instance->addExtension(${($_ = isset($this->services['oro_entity.twig.extension.entity']) ? $this->ser $instance->addExtension(${($_ = isset($this->services['twig.extension.intl']) ? $this->services['twig.e $instance->addExtension(${($_ = isset($this->services['oro_locale.twig.date_time_organization']) ? $thi $instance->addExtension(${($_ = isset($this->services['oro_calendar.twig.dateformat']) ? $this->service $instance->addExtension(${($_ = isset($this->services['oro_calendar.twig.recurrence']) ? $this->service $instance->addExtension(${($_ = isset($this->services['oro_currency.twig.currency']) ? $this->services[ $instance->addExtension(${($_ = isset($this->services['twig.extension.routing']) ? $this->services['twi
这是编译器最终得到的getOroEmail_EmailRendererService.php的内容,如您所见,它缺少我的扩展名。我该如何解决?
答案 0 :(得分:0)
用于渲染文件的树枝和用于渲染电子邮件模板的树枝不是同一实例。 ORO CRM是对Twig功能的扩展,用于呈现电子邮件模板,请参见Oro\Bundle\EmailBundle\Provider\EmailRendered
。我找不到与此标签相关的任何标签,因此您可能需要CompilerPass才能为EmailRenderer添加扩展名。