回答:
{% if var == constant('Namespace\\Entity::TYPE_PERSON') %}
{# or #}
{% if var is constant('Namespace\\Entity::TYPE_PERSON') %}constant関数とconstantテストのドキュメントを参照してください。
時間を節約するだけです。名前空間でクラス定数にアクセスする必要がある場合は、
{{ constant('Acme\\DemoBundle\\Entity\\Demo::MY_CONSTANT') }}{% if var == object.MY_CONSTANT %}
                    1.12.1以降、オブジェクトインスタンスから定数を読み取ることもできます。
{% if var == constant('TYPE_PERSON', entity){{ constant('Namespace\\Classname::CONSTANT_NAME') }}(doc)と書いてください
                    {{ constant('TYPE_PERSON', entity) }}に使用したい場合は、次のようにすることができます(インスタンス化エンティティクラス)$this->render('index.html.twig', ['entity' => new Entity()]);
                    編集:私はより良い解決策を見つけました、それについてはこちらをお読みください。
あなたがクラスを持っているとしましょう:
namespace MyNamespace;
class MyClass
{
    const MY_CONSTANT = 'my_constant';
    const MY_CONSTANT2 = 'const2';
}Twig拡張機能を作成して登録します。
class MyClassExtension extends \Twig_Extension
{
    public function getName()
    { 
        return 'my_class_extension'; 
    }
    public function getGlobals()
    {
        $class = new \ReflectionClass('MyNamespace\MyClass');
        $constants = $class->getConstants();
        return array(
            'MyClass' => $constants
        );
    }
}これで、Twigで定数を使用できます。
{{ MyClass.MY_CONSTANT }}constant()、FQNでの使用は面倒です。
                    名前空間を使用している場合
{{ constant('Namespace\\Entity::TYPE_COMPANY') }}重要!シングルスラッシュではなく、ダブルスラッシュを使用する
Symfonyの本のベストプラクティスには、この問題に関するセクションがあります。
constant()関数のおかげで、たとえばTwigテンプレートで定数を使用できます。
// src/AppBundle/Entity/Post.php
namespace AppBundle\Entity;
class Post
{
    const NUM_ITEMS = 10;
   // ...
}そして、テンプレート定数でこの定数を使用します:
<p>
    Displaying the {{ constant('NUM_ITEMS', post) }} most recent results.
</p>ここにリンク:http : //symfony.com/doc/current/best_practices/configuration.html#constants-vs-configuration-options
数年後、私の以前の答えはあまり良くないことに気づきました。問題をよりよく解決する拡張機能を作成しました。オープンソースとして公開されています。
https://github.com/dpolac/twig-const
これは#、クラスの任意のオブジェクトを介してクラス定数にアクセスできる新しいTwigオペレーターを定義します。
そのように使用してください:
{% if entity.type == entity#TYPE_PERSON %}
User#TYPE_PERSON、オブジェクトをインスタンス化せずにエンティティクラス名を使用する場合は、NodeExpressionクラスを次のように変更できます->raw('(constant(\'App\\Entity\\' . $this->getNode('left')->getAttribute('name') . '::' . $this->getNode('right')->getAttribute('name') . '\'))')。もちろん、これはクラスをApp\Entity名前空間に制限しますが、これは最も一般的なユースケースをカバーすると思います。
                    
{% if var is constant('TYPE_PERSON', object) %}