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
Post a Comment