文章

顯示從 6月, 2025 起發佈的文章

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

JSON:API Extras(can shorten API URL / customization)

  JSON:API Extras :  Use the JSON:API Extras module to customize JSON:API responses by specifying automatic includes. For example, if you have a node with a taxonomy term entity reference, you can specify that as an automatic include, which will then be parsed by the JSON:API Include module. default ?include=

《Drupal 12 製造手冊》目錄

  序章:預見未來 Drupal 12 1.1 Drupal 的演進:從 monolith 到 headless 1.2 為何選擇 Headless Drupal 12?新時代的內容中樞 1.3 本書指南:掌握未來開發的藍圖 第一部分:Drupal 12 核心解構與 Headless 基礎 2.1 Drupal 12 核心架構:面向 API 的徹底改造 2.2 CMI (Configuration Management Initiative) 2.0:雲原生配置管理 2.3 內容實體 (Content Entities) 的進化:數據模型的靈活性與一致性 2.4 權限與認證機制:OAuth 2.0 與 JWT 深度整合 2.5 內置 API 網關:安全、高效的數據通道 第二部分:數據暴露與 API 設計藝術 3.1 GraphQL 原生支援:精確數據查詢與高效能 3.2 RESTful API 實踐:資源建模與最佳實踐 3.3 實時數據流:WebSockets 與內容訂閱 3.4 API 版本管理策略:向前兼容與平滑升級 3.5 自定義 API 端點:使用低代碼工具構建 第三部分:未來內容創作與 Headless 工作流 4.1 解耦編輯器:打造個性化的內容創作體驗 4.2 Headless 預覽機制:所見即所得的即時反饋 4.3 多渠道內容分發策略:一次創作,多處呈現 4.4 AI 輔助內容生成與優化:提升內容價值 4.5 自動化工作流:CI/CD 驅動的內容發佈流程 第四部分:Headless 前端整合與實踐 5.1 前端框架選擇:React, Vue, Svelte, Next.js, Nuxt.js 5.2 狀態管理與數據同步:前端數據流的最佳實踐 5.3 圖片與媒體優化:響應式與 CDN 策略 5.4 用戶體驗與性能優化:Lighthouse 指標與 Core Web Vitals 5.5 SEO 策略:Headless 環境下的搜尋引擎優化 第五部分:部署、擴展與維護 6.1 雲原生部署:Docker 與 Kubernetes 實戰 6.2 無服務器架構 (Serverless):函數即服務 (FaaS) 的應用 6.3 性能監控與日誌分析:確保系統穩定運行 6.4 安全最佳實踐:保...