Twig 扩展 - symfony2 环境 [英] Twig extension - symfony2 environment

查看:40
本文介绍了Twig 扩展 - symfony2 环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个有效的扩展程序,这取决于环境.如何在扩展类中检索当前环境的名称?什么是最佳做法?

im trying to write an extension that works will depend on the environment. How to retrieve the name of the current environment inside the extension class? What is best practices?

推荐答案

您必须在扩展构造函数中注入参数.

You'll have to inject the parameter in your extension constructor.

或者,您可以将 twig 模板中的当前环境称为 app.environment.

Either, you may refer to current envinroment in twig templates as app.environment.

这篇关于Twig 扩展 - symfony2 环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆