`base_template_class` php twig模板的替代方案
从#3.0.0-beta1(2019-11-11)上的更改日志中,
- 删除了twig \环境上的“ base_template_class”选项,
我的自定义模板类从twig> twig \ template
> 覆盖display()
和render()
函数
public function display(array $context, array $blocks = null)
{
$env = $this->env;
$env->addTemplateStack($this->getTemplateName());
if (is_array($blocks))
{
$env->current_inheritance_level++;
$this->inheritance_level = $env->current_inheritance_level;
$env->active_inheritance_level = $env->current_inheritance_level;
parent::display($context, $blocks);
}
else {
// Call to the deepest template or include
parent::display($context, []);
}
}
public function render(array $context)
{
$env = $this->env;
$this->inheritance_level = 0;
$env->active_inheritance_level = 0;
$env->current_inheritance_level = 0;
return parent::render($context);
}
,但使用twig v3 base_template_class_class
选项已删除选项 因此,我必须使用原始显示&渲染功能。 在V3上拥有此类数据的替代方法是什么
From the change log on # 3.0.0-BETA1 (2019-11-11)
- removed the "base_template_class" option on Twig\Environment
I have a custom Template class extend from Twig\Template
which override the display()
and render()
function
public function display(array $context, array $blocks = null)
{
$env = $this->env;
$env->addTemplateStack($this->getTemplateName());
if (is_array($blocks))
{
$env->current_inheritance_level++;
$this->inheritance_level = $env->current_inheritance_level;
$env->active_inheritance_level = $env->current_inheritance_level;
parent::display($context, $blocks);
}
else {
// Call to the deepest template or include
parent::display($context, []);
}
}
public function render(array $context)
{
$env = $this->env;
$this->inheritance_level = 0;
$env->active_inheritance_level = 0;
$env->current_inheritance_level = 0;
return parent::render($context);
}
But with Twig V3 base_template_class
option was removed
So I have to use the original display & render function instead.
What is the alternative to having these kinds of data on V3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论