/**
* 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. | 関連モジュール | タイトル |
|---|---|---|---|
| 言語 | 7.15 | Language | まだ翻訳されていない英語文、どうにかならない? |
| テーマ | 7.15 | CSS Injector | 簡単にCSSを追加したい |
| コンテンツの管理 | 6.x | Views Flag Calendar | 空き室予約のような仕組みは実現できますか? |
| コンテンツの作成 | 6.x | Views | カルーセルのように回転するコンテンツを作りたい |
| アップデート | 7.15 | Webform Backup_and_Migrate | drupal7.12 -> drupal7.14アップデートメモ |
| フォーム | 7.15 | Webform | WebformのEntity Translation |
| フォーム | 7.15 | Webform | Webform - 確認ページの多言語化 |
| コンテンツの作成 | 7.15 | Automatic_Nodetitles Automatic_Entity_Label | ノード投稿フォームにタイトル入力フォームを表示しない方法 |