【发布时间】:2013-04-13 10:22:01
【问题描述】:
我有一个代码可以检查树枝模板中的一些实体常量:
{% if logRecord.status is constant('App\\DealBundle\\Entity\\Deal::DEAL_STATE_MONEY_RESERVED') %}
但是每次都用这么长的类名实在是太尴尬了。有没有办法在 twig 中创建命名空间别名?比如:
{% use App\\DealBundle\\Entity\\Deal %}
{% if logRecord.status is constant('Deal::DEAL_STATE_MONEY_RESERVED') %}
或者我总是需要写完整的类名?
【问题讨论】:
-
你总是需要写完整的类名。有没有想过creating a twig test 这样你就可以像
if logRecord.status is state('reserved')那样做? -
是的,你可以为此编写一个 twig 函数。
-
@Maerlyn 是的,我可能会为它进行自定义测试。谢谢!
标签: php symfony namespaces twig