2016-12-16 37 views
0

我有一個自定義的內容類型,有價格,產品摘要,產品圖像等幾個字段。有沒有什麼辦法可以在搜索結果頁面上分別訪問這些字段?Drupal 8 - 如何自定義搜索結果模板

我使用kint(item.value)這表明我只能訪問titleurltype分別像{{ item.value['#result'].url }}{{ item.value['#result'].title }}印刷在mytheme/item-list.html.twig渲染陣列。但是在渲染數組中看不到諸如product_imageproduct_summary等變量。

根據樹枝模板建議,我需要覆蓋的模板是search-result.html.twig。所以我複製/core/themes/stable/templates/content/search-result.html.twig我的主題的文件夾。但是,{{ snippet }}變量沒有我想要訪問的信息。

我通過以下步驟去定製結果輸出:。

  1. 走到/admin/structure/types/manage/product/displayStructure > Content Types > Product > Manage Display)車削上Search IndexSearch result highlight input

enter image description here

  • 導航到Search result highlight input選項卡並添加(啓用)兩個字段產品摘要和產品噸價
  • enter image description here

  • 回到搜索結果,但我仍然無法看到在渲染陣列那些變量。
  • 請問有人能告訴我完成上述的最佳方法嗎?

    回答

    1

    @Subrata Sarkar有一個選項。首先,從drupal.org

    安裝兩個模塊search_api和search_api_page模塊

    https://www.drupal.org/project/search_api

    https://www.drupal.org/project/search_api_page enter image description here

    添加服務器和索引的搜索API。 添加要在索引內的頁面上顯示的字段,並在所有配置索引完所有數據後添加。 enter image description here

    此創建和配置搜索page.And選擇視圖模式選項,選擇一種視圖模式除權後:搜索結果突出顯示輸入或搜索索引等 enter image description here

    希望你得到的搜索頁面上你想要的結果。欲瞭解更多信息,請致電 https://www.youtube.com/watch?v=dNilEVQu94I

    +0

    感謝您的詳細解答。我會盡快嘗試你的建議,並回復你所得到的結果。 –