A lot of users want to get an overview of the latest items of a list or library. Some users want to include a link to the list or library from which the items were retrieved. As this link from the search results location may vary, you should not hard code the link back to the item or control template.
Solution
The solution is very easy. By default you have a managed property called ParentLink. You need to add this property to the ManagedPropertyMapping attribute inside your item display template.
|
|
Next, you should add some extra code to the item template.
Note: You could choose to add extra code to the control template instead but it requires that you write more code.
The link only needs to be shown if the last item gets processed. This means that the code needs to check to see when the last item gets processed. In a post on my blog I showed how you could include alternating row styling. I also explain how you can check if the last row is rendered: Showing Alternating Rows in the Content Search WebPart (Display Template).
To check if the last row is processed, you should include the following code in the Item Template:
|
|
Place it at the bottom of your Item Template and you get the following result:
Important: This only works if your items are coming from the same library. Otherwise View all will link to the list or library location of the last item.
Download
You can download the template that I created for this post on GitHub: Item display template with view all link to list or library.