如何在 SharePoint Server 中的動態顯示面板中顯示自訂受管理屬性的值How to display values from custom managed properties in the hover panel in SharePoint Server

摘要: 了解如何在 SharePoint Server 中的動態顯示面板中顯示自訂受管理屬性的值。Summary: Learn how to display values from custom managed properties in the hover panel in SharePoint Server.

我們顯示您如何顯示如何從搜尋結果-選項 2 in SharePoint Server 中的自訂受管理屬性的值在自訂的值 managed 屬性與結果醒目提示,並取得根據使用者自動改進的相關性[表現方式。在本文中,您將了解:In How to display values from custom managed properties in search results - option 2 in SharePoint Server we showed you how to display values from custom managed properties with hit highlighting, and get automatically improved relevancy based on end-user click behavior. In this article, you'll learn:

如何決定要修改的動態顯示面板顯示範本How to decide which hover panel display template to modify

我們執行任何作業之前,我們先重新整理在不同的顯示範本如何彼此相連我們記憶:Before we do anything, let's first refresh our memories on how the different display templates are connected:

關聯 2

  1. 每個結果類型會包含一個項目顯示範本的參照。Each result type contains a reference to an item display template.

  2. 每個項目顯示範本包含以動態顯示面板顯示範本的參照。Each item display template contains a reference to a hover panel display template.

  3. 每個項目顯示範本包含一般的項目顯示範本的參照。Each item display template contains a reference to the common item display template.

  4. 每個所參照的動態顯示面板顯示範本包含三個一般動態顯示面板顯示範本的參照。Each referenced hover panel display template contains references to three common hover panel display templates.

根據預設,在動態顯示面板的轉譯是由三個一般動態顯示面板顯示範本執行。下圖顯示如何一般動態顯示面板顯示範本用來呈現我們搜尋中心的案例中預設動態顯示面板。By default, the rendering of the hover panel is performed by the three common hover panel display templates. The illustration below shows how the common hover panel display templates were used to render the default hover panel in our Search Center scenario.

預設呈現

當您新增自訂屬性至動態顯示面板盡 life,進行應該維持下列三個一般動態顯示面板顯示範本,以及改用專注於結果類型特定動態顯示面板顯示範本 (以醒目提示下圖)。這是我們並未在搜尋中心案例中,很我們將會示範本文中。To make life as easy as possible when you are adding custom properties to your hover panel, you should leave these three common hover panel display templates as they are, and instead concentrate on the result type specific hover panel display template (highlighted in the illustration below). That's what we did in our Search Center scenario, and it's what we'll demonstrate in this article.

動態顯示面板顯示範本

這可能會看起來費解現在,但是我們將顯示所有您下一步] 兩個章節中所需的步驟。讓我們開始吧 !This may seem confusing now, but we'll show you all the the steps that are required in the next two sections. So let's get started!

如何將複製現有的動態顯示面板顯示範本How to copy an existing hover panel display template

我們建立的自訂項目顯示範本TechNet 內容時,請記得、 我們開始複製名為Item_Default的項目顯示範本 (如需詳細資訊,請參閱如何建立新的結果類型 in SharePoint Server )。Item_Default顯示範本包含Item_Default_HoverPanel動態顯示面板顯示範本的參照。因為我們複製Item_Default顯示範本,我們TechNet 內容顯示範本也包含Item_Default_HoverPanel的參照。Remember when we created the custom item display template TechNet content , we started by copying the item display template named Item_Default (see How to create a new result type in SharePoint Server for more information). The Item_Default display template contains a reference to the Item_Default_HoverPanel hover panel display template. Because we copied the Item_Default display template, our TechNet content display template also contains a reference to the Item_Default_HoverPanel .

項目預設連結

我們想要使用Item_Default_HoverPanel動態顯示面板顯示範本作為基礎當我們新增到我們動態顯示面板的自訂屬性。因此,我們對應的網路磁碟機中我們複製Item_Default_HoverPanel顯示範本We wanted to use the Item_Default_HoverPanel hover panel display template as a basis when we added custom properties to our hover panel. Therefore, in our mapped network drive, we copied the Item_Default_HoverPanel display template

已顯示的項目預設

並指定其新名稱: TechNet_Content_HoverPaneland gave it a new name: TechNet_Content_HoverPanel .

TechNet 動態顯示面板

我們只需要重新命名 HTML 檔案中,因為相關聯的 JavaScript 檔案的名稱會自動更新。We only had to rename the HTML file, because the name of the associated JavaScript file was automatically updated.

在 TechNet 內容的顯示範本中,我們會變更var hoverUrl中的參照使其指向新複製並重新命名TechNet_Content_HoverPanel顯示範本。In the TechNet content display template, we changed the reference in var hoverUrl so that it pointed to the newly copied and renamed TechNet_Content_HoverPanel display template.

新變數動態顯示 URI

如何變更要顯示自訂受管理屬性的值的動態顯示面板顯示範本How to change a hover panel display template to show values from custom managed properties

在搜尋中心案例中,預設動態顯示面板包含幾乎沒有其他搜尋結果的相關資訊。In our Search Center scenario, the default hover panel contained almost no additional information about the search result.

預設動態顯示面板

我們想要將值從下列四個的網站欄新增至動態顯示面板:We wanted to add the values from the following four site columns to the hover panel:

  • GUID/UUIDGUID/UUID

  • 內部編寫器Internal Writer

  • 狀態Status

  • 送出連絡人Submission Contact

下列螢幕擷取畫面顯示如何這些值會維持在內部清單中的一個項目。The following screen shot shows how these values are maintained for one item in our internal list.

清單項目

時新增自訂屬性至動態顯示面板,我們已將其新增至項目顯示範本(下圖中反白顯示)。When adding custom properties to a hover panel, we have to add them to the item display template (highlighted in the illustration below).

同樣地,因為這不是真正直覺式:時新增自訂屬性的動態顯示面板中,我們已將它們新增至項目顯示範本Again, because this is not really intuitive: When adding custom properties to a hover panel, we have to add them to the item display template .

結果類型特定 DT

若要顯示在動態顯示面板,以下的自訂屬性應該怎麼做:To display custom properties in the hover panel, here's what you should do:

  1. 尋找您想要使用的網站欄的 managed 的屬性名稱。如何顯示搜尋結果-選項 1 in SharePoint Server 中的自訂受管理屬性的值會顯示如何執行這項作業。Find the managed property names of the site columns that you want to use. How to display values from custom managed properties in search results - option 1 in SharePoint Server showed how to do this.

  2. 開啟包含您要自訂的動態顯示面板顯示範本參照的項目顯示範本。ManagedPropertyMapping tag 中項目顯示範本請新增您想要顯示自訂受管理的屬性使用下列語法:Open the item display template that contains the reference to the hover panel display template that you want to customize. In the item display template, in the ManagedPropertyMapping tag, use the following syntax to add the custom managed properties that you want to display:

    '<Current item property name>':<Managed property name>'
    

    在搜尋中心案例中,我們可以新增四個 managed 的屬性TechNet 內容項目顯示範本。In our Search Center scenario, we added four managed properties to the TechNet content item display template.

    已新增 MP

  3. 注意

    您執行作業需要執行此步驟如果您使用 SharePoint Online。You do not have to do this step if you are using SharePoint Online.

    移至 [網站設定 --> 搜尋結果類型。請注意屬性同步處理通知會顯示。Go to Site settings --> Search Result Types. Notice that a Property Sync alert is displayed.

    屬性同步處理警示

    顯示此警示是因為我們已新增新的 managed 的屬性 (我們進行了這在步驟 2) 項目顯示範本。若要以新加入的 managed 屬性更新結果類型,選擇 [更新]。This alert is displayed because we have added new managed properties to an item display template (we did this in step 2). To update the result types with the newly added managed properties, choose Update.

    已更新 MP

    重要

    如果您不執行更新,新加入的 managed 的屬性將不會顯示在動態顯示面板。If you don't do the update, the newly added managed properties won't display in your hover panel.

  4. 開啟在動態顯示面板顯示範本您要變更,並使用 HTML 」 來新增您想要顯示的自訂屬性。Open the hover panel display template that you want to change, and use HTML to add the custom properties that you want to display.

    在搜尋中心案例中,我們會開啟TechNet_Content_HoverPanel 。下列螢幕擷取畫面顯示我們如何新增我們四個自訂屬性。In our Search Center scenario, we opened the TechNet_Content_HoverPanel . The following screen shot shows how we added our four custom properties.

    顯示屬性

  5. 儲存檔案。Save the file.

透過新的搜尋並停留自訂的搜尋結果,我們看到現在已顯示四個自訂屬性。好 !By doing a new search and hovering over a search result, we saw that the four custom properties were now displayed. Nice!

已顯示的自訂屬性

但是,我們還不是完全透過。內部作者送出連絡人的值是以不同方式顯示。螢幕擷取畫面可能不會顯示它清楚,但希望您所見內部編寫器的值已顯示,但送出連絡人的值是非常長同時包含美觀的 GUID。But, we are not completely through yet. The values for Internal Writer and Submission Contact were displayed differently. The screen shot might not show it clearly, but hopefully you can see that the value for Internal Writer was displayed well, but the value for Submission Contact was very long and contained an ugly GUID.

這兩個這些值是來自於網站欄的個人或群組的類型。不同的是在網站欄設定] 中,內部編寫器設定為顯示名稱] 中,而送出連絡人已設定為顯示名稱 (與目前狀態)Both these values come from a site column of type Person or Group. The difference is that in the site column settings, Internal Writer is configured to show Name, whereas Submission Contact is configured to show Name (with presence).

網站欄設定

若要讓正確顯示送出連絡人,我們會複製HP。GetAuthorsHtml使用Item_CommonHoverPanel_Body顯示範本用來顯示作者的方法。To make Submission Contact display correctly, we copied the HP.GetAuthorsHtml method that is used by the Item_CommonHoverPanel_Body display template to display authors.

作者方法

而現在真正優尋找已啟動動態顯示面板。And now the hover panel was starting to look really good.

最終動態顯示面板

但如果要讓動態顯示面板更為實用,我們想要新增動作至動態顯示面板的底部。會顯示如何這樣這樣。But to make the hover panel even more helpful, we wanted to add an action to the bottom of the hover panel. will show how to do this this.

本系列中的下一篇文章Next article in this series

如何將自訂動作新增至 SharePoint Server 中的動態顯示面板How to add a custom action to the hover panel in SharePoint Server