/** * Implements hook_preprocess_HOOK() for html.html.twig. */ function your_theme_preprocess_html(array &$variables) { $current_path = \Drupal::service('path.current')->getPath(); $alias = explode('?', $_SERVER['REQUEST_URI']); $alias = $alias[0]; // Node type. if (preg_match('!^/node/([0-9]+)!', $current_path, $m)) { $variables['attributes']->addClass("node--$m[1]"); } // Alias. if ($alias) { $aliases = explode('/', $alias); array_shift($aliases); $suggestion = []; foreach ($aliases as $a) { $suggestion[] = $a; $variables['attributes']->addClass(implode('--', $suggestion)); } } }
bodyタグにnode idやaliasのClassを追加する方法
OTHER FAQ
カテゴリ | Core Ver. | 関連モジュール | タイトル |
---|---|---|---|
Commerce2 | 8.6.x | Commerce Order | Commerceで注文情報から全Itemを得る方法 |
Commerce | 8.6.x | Commerce Payment Gateway | オリジナルCommerce決済モジュール(Offsite)で決済サーバーへのPOST時のエンコードを変更する方法 |
Commerce | 8.6.x | Commerce Payment Order | Commerceで歴代購入数/金額を集計する方法 |
Commerce | 7.34 | Commerce kickstart, Commerce file | Commerceモジュール利用時のダウンロード製品登録方法 |
CentOS | 7.50 | 消せないファイルを消すには | |
Calendar | 7.34 | Calendar | CalendarモジュールとGoogleカレンダーを同期するには |
Apache2.4 | 7.50 | Apache2.4のアクセス制限 |