الاختبار constant في Twig

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث

يتحقق الاختبار constant إذا كان المتغير له نفس القيمة التي للثابت، ويمكن استخدام الثوابت العامة global constants هنا أو ثوابت الأصناف:

{% if post.status is constant('Post::PUBLISHED') %}
    the status attribute is exactly the same as Post::PUBLISHED
{% endif %}

يمكن اختبار الثوابت من نُسخ الكائن:

{% if post.status is constant('PUBLISHED', post) %}
    the status attribute is exactly the same as Post::PUBLISHED
{% endif %}

انظر أيضًا

المصادر