ข้ามไปยังเนื้อหาหลัก
หน้าแรก
DrupalThailand

Main navigation

  • หน้าแรก
  • ฟอรั่ม
  • ประกาศงาน
  • บทความ
  • กิจกรรม
User account menu
  • เข้าสู่ระบบ

การแสดงเส้นทาง

  1. หน้าแรก
  2. บทความ

เพิ่ม class body tag ตาม path เว็บไซต์

By admin, 7 สิงหาคม, 2021

แก้ไขที่  .theme ใน folder Theme ของคุณ  แล้ว โค้ดที่ได้จากข้างล่างนี้  
(THEMENAME  เปลี่ยนเป็นชื่อ Theme ของคุณเอง)

/**
 * Implements hook_preprocess_html().
 */
function THEMENAME_preprocess_html(&$vars) {
  // Get the current path
  $current_path = \Drupal::service('path.current')->getPath();
  $internal = \Drupal::service('path_alias.manager')->getAliasByPath($current_path);

  // Assign it to body class 
  $vars['attributes']['class'][] = str_replace("/", "", $internal);
}

Tags

  • drupal8
  • drupal
  • css
  • theme
  • Log in or register to post comments

Comments

Releases for Drupal core

drupal 9.3.17

Releases for Drupal core

drupal 9.4.1

Releases for Drupal core

drupal 10.1.x-dev

Releases for Drupal core
More posts about Releases for Drupal core

Tags

  • ธีม
  • docker
  • css
  • mac
  • drupal8
Powered by Drupal Thailand