Changing the Sift Results Layout

When you install Sift a _SiftDefaultResults partial view is added that provides a default layout for the search results. This partial view is rendered in the results <div> to display the search results. There is nothing to stop you updating this partial view to meet your requirements. However, I would recommend creating separate partial views for your filter results.

You specify which partial view to display by adding the data-sift-result-partial to the outer <div> of a sift block. Do not include the ".cshtml" extension.

  1. @inherits Umbraco.Web.Mvc.UmbracoViewPage
  2.  
  3. <h1>Results Partial View Filter</h1>
  4.  
  5. <div class="sift"
  6. data-sift-result-document-type="cinemaCento"
  7. data-sift-result-partial="_SiftResultsPartialExample">
  8.  
  9. <form class="sift-criteria">
  10.  
  11. @Html.AntiForgeryToken()
  12.  
  13. <label for="filmName">Name</label>
  14. <input type="text" id="filmName" name="filmName"
  15. class="sift-criterion"
  16. data-sift-match-property="nodeName" />
  17. <p></p>
  18.  
  19. <input type="submit" value="Search" />
  20.  
  21. </form>
  22.  
  23. <div class="sift-result">
  24. </div>
  25.  
  26. </div>
  27.  
  28. <script src="~/Scripts/sift.js" type="text/javascript"></script>

The partial view should accept a SearchResultNodes object, which includes a Nodes property with a list of IPublishedContent references to the content found. It also contains the Criteria information and details on the number of results and number of pages returned.

Take a look at _SiftDefaultResults for an example of how this information can be used. The following results partial example displays the date and star rating for the films returned.

  1. @model SiftLibrary.Models.SearchResultNodes
  2.  
  3. @foreach (var node in Model.Nodes)
  4. {
  5. var formattedDate = node.Value<DateTime>("date").ToString("dd MMM yyyy");
  6. var numStars = node.Value("starRating") + " stars";
  7.  
  8. <a href="@node.Url()">@node.Name()</a><br/>
  9. @formattedDate<br/>
  10. @numStars
  11. <hr />
  12. }

When rendered this looks like this.

Sift result partial view

<< Back to User Guide