php - Use namespace alias in twig -


i have code checks entity constant in twig template:

{% if logrecord.status constant('app\\dealbundle\\entity\\deal::deal_state_money_reserved') %} 

but embarrassing use such long class name everytime. there way make namespace alias in twig? like:

{% use app\\dealbundle\\entity\\deal %} {% if logrecord.status constant('deal::deal_state_money_reserved') %} 

or need write full class names?

you can use macro :

{% macro state(name) -%}    {{ constant('app\\dealbundle\\entity\\deal::deal_state_' ~ name) }} {%- endmacro %} 

and use way :

{% if logrecord.status == _self.state('money_reserved') %} 

don't forget use hyphens ( - ) remove whitespaces in macro.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -