Search title - how to refer to the search query

Topics: Customizing Orchard, General
Apr 7, 2014 at 3:24 PM
On my search page I would like to add the term being searched for into the title.
For example if the search term was 'housing' I would like my page title to read: 'Search Results for 'housing'.'

I understand how to do this by creating an alternate but I am unsure of the code to use to refer to the term being searched for.

Any ideas please?

Thanks,
Kirsty
Apr 7, 2014 at 3:34 PM
Create a folder "Orchard.Search" in your theme. Then inside that folder create a folder called "Search" and inside that folder create a shape template "Index.cshtml"
@using Orchard.ContentManagement;
@using Orchard.UI

@model Orchard.Search.ViewModels.SearchViewModel
@{
    Style.Require("Search");

    Layout.Title = T("Search Results for ") + Model.Query.ToString();

    IEnumerable<object> searchResults = Model.ContentItems;
    Model.ContentItems.Classes.Add("content-items");
    Model.ContentItems.Classes.Add("search-results");
}
<h1>@Html.TitleForPage(T("Search").Text) : @Model.Query.ToString()</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)
} 
Best
Abhishek Luv
Apr 8, 2014 at 10:08 AM
Thanks so much for your reply Abhishek, it works a treat!

Kirsty