This project is read-only.

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?

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

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

    IEnumerable<object> searchResults = Model.ContentItems;
<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>
        <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())
Abhishek Luv
Apr 8, 2014 at 10:08 AM
Thanks so much for your reply Abhishek, it works a treat!