2017-11-11 6 views
0

私はビュー内のティーザーのリストを表示します。 このコンテンツタイプには、このビューが含まれています。 このコンテンツタイプのすべてのページに表示されます。Drupal 8 /どのように私は、現在のノードが同じ場合は、ビューリスト内に追加クラス/強調 'ビューアイテム'を追加するのですか?

どのように私はアクティブにすることができますので、ビューアイテムにクラスを追加するのですか?

答えて

0

は、ビューをレンダリングしているかに依存し、あなたはあなたが一度あなたがプリプロセッサにいくつかのロジックを追加することができ、グリッドの例は

function MYTHEME_preprocess_views_view_grid(&$variables) {} 

をレンダリングするプリプロセッサを使用して、このロジックに従ってクラスを追加する必要があります

function MYTHEME_preprocess_views_view_grid(&$variables) { 
    $options = $variables['view']->style_plugin->options; 
    $item_num = 0; 
    $items = []; 

    // Iterate over each rendered views result row. 
    foreach ($variables['rows'] as $item) { 
    // Add item attributes 

    $item_attrs = []; 
    $item_attrs['class'] = "view-grid__item view-grid__item--{$item_num}"; 
    $items[$item_num]['attributes'] = new Attribute($item_attrs); 

    // Add item.content 
    $items[$item_num]['content'] = $item; 

    // Increase, decrease or reset appropriate integers. 
    $item_num++; 

     } 

    // Add items to the variables array. 
    $variables['items'] = $items; 
} 

ここ https://api.drupal.org/api/drupal/core!modules!views!views.theme.inc/function/template_preprocess_views_view/8.2.x

の詳細情報を参照してください。
関連する問題