2017-06-05 10 views
0

Drupal 8の分類用語テンプレートページで作業しています。内容を入力するタクソノミー用語のみに基づいて特定のコンテンツを表示できる必要がありますページ。 taxonomy-term.twig.htmlテンプレートを出発点として使用していますが、文字列値と{{name}}変数を比較することはできません。ここで私が持っているコードは、これまでです:名前変数とDrupal 8の文字列値を比較するtwigテンプレート

<section{{ attributes.addClass(classes)}}> 
    {% if 'general' in name %} 
     <img class="promo-image" src="http://placehold.it/150x150" alt="promo"> 
     <h3 class="promo-title">Promo title text</h3> 
     <p class="promo-copy">lorem ipsum dolor set amet</p> 
     <div class="links"> 
      <a href="/resources" class="btn outline-black-transparent">Learn more</a> 
     </div> 
    {% endif %} 
</section> 

I出力した場合、{{名前}}通常のような名前の変数が、それはページにタグ名を出力しますが、私は反対値を比較する方法を見つけ出すことはできません何でも私はまっすぐのifルートも試しましたが、名前変数が配列であるようです。

答えて

0

名前の変数が配列である、と私は私が追加された最初の値が必要なので:今すぐテンプレートが道を働いている

{% if tag == 'text' %} 
<section{{ attributes.addClass(classes)}}> 
    <img class="promo-image" src="http://placehold.it/150x150" alt="promo"> 
    <h3 class="promo-title">Promo title text</h3> 
    <p class="promo-copy">lorem ipsum dolor set amet</p> 
    <div class="links"> 
     <a href="/resources" class="btn outline-black-transparent">Learn more</a> 
    </div> 
</section> 
{% endif %} 

:にif文を変更すると

{% 
set tag = name['#items'].0.value 
%} 

を私は意図した。

関連する問題