How to Add a ‘Go To Library’ Button on SharePoint 2013 Search Results

I’ve recently been working on some usability features for our SharePoint deployment, and I’ve come up with a few new things which I’ll be releasing in the next few days hopefully.

This is a small but helpful one, this feature can generally be found in the hover panel on search results, but I’ve been told that Mac’s in particular don’t like the hover panel so I decided to add one of the more helpful features located on it into the search results directly.

How to Add the ‘Go To Library’ Feature

1. Locate the Item_CommonItem_Body.html file which can be found in https://SharePoint-Address/_catalogs/masterpage/Forms/AllItems.aspx, it should be about 2/3rds of the way down the page.

2. Download a copy of the file by hovering the cursor over the column containing the file which should display a small downwards facing arrow. Upon clicking this a menu will open.

3. Click Download a copy to begin downloading the file, Once it’s downloaded open the file in any text editing program that can be used for coding. (generally anything but Word)

5. Around line 87 you will find “_#= titleHtml =#_”, after the closing H3 tag around this create a few lines space to put the code that I will give you below.

6. Once you’ve got some space enter the code below (I’ll explain exactly what the different parts do at the bottom of this guide.

<!–#_ if (!$isEmptyString(ctx.CurrentItem.csr_Icon)) {  _#–>
<a href=”_#=ctx.CurrentItem.ParentLink=#_”>Click to go to Library</a>
<!–#_ } _#–> 

7. Save the file and open up the page you downloaded it from again.

8. Click Files at the top-left to open the files menu.

9. Click Upload Document and browse to the file you have just edited.

10. Click Open followed by OK on the Add a master page dialog, this will upload your file again.

11. Another popup will now appear, simply click Check In to finish the process.

12. Do any search that shows files and you should now see the “Click to go to Library” link below the titles of each search result.

Explanation of Code

#_     _# tells SharePoint that there is script in-between those markers.

if (!$isEmptyString(ctx.CurrentItem.csr_Icon)) is a bit of JavaScript  that checks if the current search result has an icon displayed (Which would mean it is a document of some sorts), it does this by using the SharePoint function

ctx.Currentitem.csr_Icon which would be empty if there is no icon. However if the icon is displayed the code continues to execute which then displays the link to the library.

_#=ctx.CurrentItem.ParentLink=#_ is also a built in SharePoint function which contains the parent link of any current item which in this case helpfully grabs the address of the containing library dynamically.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.