我有一個自定義的內容類型,有價格,產品摘要,產品圖像等幾個字段。有沒有什麼辦法可以在搜索結果頁面上分別訪問這些字段?Drupal 8 - 如何自定義搜索結果模板
我使用kint(item.value)
這表明我只能訪問title
,url
和type
分別像{{ item.value['#result'].url }}
,{{ item.value['#result'].title }}
印刷在mytheme/item-list.html.twig
渲染陣列。但是在渲染數組中看不到諸如product_image
,product_summary
等變量。
根據樹枝模板建議,我需要覆蓋的模板是search-result.html.twig
。所以我複製/core/themes/stable/templates/content/search-result.html.twig
我的主題的文件夾。但是,{{ snippet }}
變量沒有我想要訪問的信息。
我通過以下步驟去定製結果輸出:。
- 走到
/admin/structure/types/manage/product/display
(Structure > Content Types > Product > Manage Display)
車削上Search Index
和Search result highlight input
- 導航到
Search result highlight input
選項卡並添加(啓用)兩個字段產品摘要和產品噸價 - 回到搜索結果,但我仍然無法看到在渲染陣列那些變量。
請問有人能告訴我完成上述的最佳方法嗎?
感謝您的詳細解答。我會盡快嘗試你的建議,並回復你所得到的結果。 –