定制Item Display样式
上一篇文章咱们介绍了如何定制Search Results Webpart整体样式,本文咱们介绍如何定制搜索结果中的每一条Item的样式
SharePoint中默认有31种Result Type, 其中包括:Person, Microsoft Access, Microsoft Excel, Microsoft OneNote, Microsoft PowerPoint, Microsoft Publisher, Microsoft Visio, Microsoft Word, Discussion, Reply, Email, Image, PDF, Text, Video, XML, Zip,SharePoint Blog, SharePoint Community,SharePoint Discussion Board, SharePoint Document Library, SharePoint List, SharePoint MicroBlog Post, SharePoint Picture Library, SharePoint Site, SharePoint Survey, SharePoint Wiki,SharePoint Picture Library List
对应SharePoint中Display Template格式为
Item_WebPage.html
Item_Word.html
Item_Person.html
.....
SharePoint中默认的Result Type中逻辑主要是作为传递MangedProperty值,页面显示主要是加载Search Result Webpart关联的Item_CommonItem_Body.html,所以定制每一个Item显示样式可以从两方面入手:
1. 在Item_WebPage.html中加额外的样式逻辑,更倾向于单独控制某一个result type的显示样式
2. 在Item_CommonItem_Body.html中加额外的样式逻辑,更倾向于统一控制,如果想加针对result type的样式,需要加js控制逻辑
主要注意点:
1. 咱们一般控制Result Type对应的显示样式的时候,会加入Custom Managed Property,需要在两个地方添加Mapping,一个是在Item的display template中,例如 Item_WebPage.html中 <mso:ManagedPropertyMapping msdt:dt="string">节点,以及Item_CommonItem_Body.html中的<mso:ManagedPropertyMapping msdt:dt="string">节点
2. 修改mso:ManagedPropertyMapping 需要去到Result Type中Update一下,这个时候SharePoint 会给出Update的提示,需要点击Update才能生效
参考文档: