文章

create_attribute()

   Drupal 中的 create_attribute 是一個非常有用的 Twig 函數,主要用於在 Twig 模板中創建和操作 HTML 屬性。它讓你能夠更靈活地為 HTML 元素添加、修改或移除屬性,例如 class、id、style 等。這對於動態生成 HTML 結構非常有幫助。✨ 簡潔說明 (Simplest Explain) 📝 create_attribute 是一個 Twig 函數,用於在 Drupal 模板中建立一個可以讓你輕鬆添加或修改 HTML 屬性的物件。你可以用它來添加 classes、設定 id 或其他屬性。 詳細說明 (Detailed Explain) 📜 create_attribute 函數在 Drupal 8.3.x 版本中引入,它讓你可以在 Twig 模板中建立一個 Attribute 物件。這個物件提供了一系列方法來方便地管理 HTML 屬性,而無需直接進行字串拼接,從而減少錯誤並提高程式碼的可讀性。 主要用途和功能: 創建一個空的 Attribute 物件: 你可以直接調用  create_attribute()  來創建一個空的物件,然後再透過其方法添加屬性。 範例: twig {% set my_attribute = create_attribute() %} {# 之後可以對 my_attribute 使用 addClass(), setAttribute() 等方法 #} 創建並初始化一個 Attribute 物件: 你也可以傳入一個屬性陣列來直接創建並初始化一個  Attribute  物件。 範例: twig <div {{ create_attribute({ 'class' : [ 'region' , 'region--header' ], 'id' : 'main-region' }) }} > {{ content }} </ div > 這會渲染成: html < div class = "region region--header" id = "main-region" > {{ content }} ...

(SSL)Unable to locate a valid CA certificate file. You must set a valid 'cafile' option.

Composer Curl error 60: SSL certificate problem Download https://github.com/composer/ca-bundle/blob/main/res/cacert.pem  composer config --global cafile 'C:\Users\______\Documents\cacert.pem'

add "+Add content" button to a view page

  function MY_MODULE_NAME_menu_local_actions_alter ( & $local_actions ) {     // Alter local actions if needed     // Check current route     $current_route = \ Drupal :: routeMatch ()-> getRouteName ();     $viewId = 'contentcontent' ;     $viewDisplay = 'page_1' ;     if ( str_starts_with ( $current_route , 'view.contentcontent' )) {                 // Add a local action button to add new content         $local_actions [ 'node.add_page' ] = [             'title' => "add" ,             'route_name' => 'node.add' ,             'route_parameters' => [                 'node_type' => 'article'             ],             'appears_on' => [   ...

hook_theme_suggestions_HOOK & hook_theme_suggestions_HOOK_alter

圖片
hook = module name HOOK = (field/ block/ paragraph ...)  您的函數 hook_theme_suggestions_HOOK  的確在生成多個模板建議,並且通過將它們放入 $suggestions 陣列並返回,間接影響了排序。Drupal 在處理主題建議時,會按照 $suggestions 陣列中元素的順序從後往前遍歷,找到第一個存在的模板。這意味著: 最後一個添加的建議具有最高優先級。

$variables['row']->_entity; entity!!!!!!!

圖片
 

control html class

function lh_theme_preprocess_html(&$variables) { $variables['attributes']['class'][] = 'inner-page'; //add a class to html , the new class = 'inner-page'

下載lang interface

 https://localize.drupal.org/translate/languages/zh-hant