Style your Search Output!

Topics: Customizing Orchard
Sep 17, 2014 at 2:39 AM
Hi!

I don't like the display of my search results. Every searchable ContentItem has an TitlePart attached. Now I want to display only this Title from the TitlePart on my searchresults.
I tried to figure out the correct alternative shape with shape tracing - but the only shape I can figure out is the Content.Summary Shape - but I think that isn't a good idea to override that one.
Is there a way to override the Content.Summary only for the search results?

Thanks
Sep 17, 2014 at 2:45 AM
benschi11 wrote:
Hi!

I don't like the display of my search results. Every searchable ContentItem has an TitlePart attached. Now I want to display only this Title from the TitlePart on my searchresults.
I tried to figure out the correct alternative shape with shape tracing - but the only shape I can figure out is the Content.Summary Shape - but I think that isn't a good idea to override that one.
Is there a way to override the Content.Summary only for the search results?

Thanks
Hello,

To style the search output create a folder called "Orchard.Search" in your views folder. Inside the Orchard.Search folder create a folder called "Search" and inside this folder create a Index.cshtml file.
@model Orchard.Search.ViewModels.SearchViewModel
@{
    Style.Require("Search");

    IEnumerable<object> searchResults = Model.ContentItems;
    Model.ContentItems.Classes.Add("content-items");
    Model.ContentItems.Classes.Add("search-results");
}
<h1>@Html.TitleForPage(T("Search").Text)</h1>

@if (HasText(Model.Query)) {
    if (!searchResults.Any()) { 
        <p class="search-summary">@T.Plural("There is <em>one</em> result", "<em>zero</em> results", searchResults.Count())</p>
    } else { 
        <p class="search-summary">@T.Plural("There is <em>one</em> result", "<em>{1} - {2}</em> of <em>{0}</em> results", Model.TotalItemCount, Model.StartPosition, Model.EndPosition)</p>
    }
}
@if (searchResults != null && searchResults.Any()) {
    @Display(searchResults)
    @Display(Model.Pager)
} 


<style type="text/css">
    ul {
        list-style: none;
    }
</style>
Hope this helps.
Regards
AL
Marked as answer by benschi11 on 9/16/2014 at 6:53 PM
Sep 17, 2014 at 2:53 AM
Thank you for the quick reply! Could have thought about myself :). Works like a charm!