This project is read-only.

Search.Search Form override & placement

Topics: Customizing Orchard, Writing themes
Jul 19, 2012 at 8:15 PM


Using the Search module on a new theme

Just trying to override and inject the /View/Part/Search.SearchForm.cshtml into the Theme layout page.

It needs to be in the Header zone (overrided as Header.cshtml) inside a specific DIV to match the designers HTML5 template.

Ive done this as a widget the easy way - this creates it as the very first item within the body tag:

<article class="widget-header widget-search-form widget">
<form action="/Search" class="search-form" method="get"><input id="q" name="q" type="text" value="" /><button type="submit" class="search-submit">Search</button>


Is there a way to specify where to inject this view part?

Using the below technique im not sure where and how to specify this?

 WorkContext.Layout.Header.Add(New.Header(), "10"); // Site name and link to the home page 

Jul 23, 2012 at 1:31 PM

I'm confused by this. The search form is a widget, and can be added to any zone. What exactly is the problem and why aren't you using the widget?

Jul 23, 2012 at 10:37 PM

Yes I can use it as a widget ok to the header zone.

Problem is it renders it immediately after the <body> tag I need it specifically within a
tag within the first <header> tag. So it's not possible to specify the exact position within a zone.

I got around it by using the razor call RenderPage("views/search form") at the point I need it

Sent from my iPad

On 23 Jul 2012, at 19:30, "bertrandleroy"<> wrote:

From: bertrandleroy

I'm confused by this. The search form is a widget, and can be added to any zone. What exactly is the problem and why aren't you using the widget?

Jul 24, 2012 at 1:01 AM

Then something is wrong with your layout.cshtml. You should fix that instead of hacking your way in.

Jul 26, 2012 at 3:49 PM

I think Layout.cshtml is fine - i'm overriding it to add the User.cshtml and SearchForm is specific places.

Using widget it renders first in the header zone l. I need it inside, the <div class="search-area"> a few elements down. Is there any way to specify this in the dashboard as position I believe adds the z-index?

    <!-- HEADER ZONE -->

<article class="widget-header widget-search-form widget">


 <div class="container_12 social">

<!--  RenderPage User Login -->       

@RenderPage(Url.Content(Html.ThemePath(WorkContext.CurrentTheme, "/Views/User.cshtml")))



<!-- header area -->

<header id="header">

<div class="container_12 cross-fade">

<div class="search-area">

 <!--  RenderPage Search module  -->             

@RenderPage(Url.Content(Html.ThemePath(WorkContext.CurrentTheme, "/Views/Parts/Search.SearchForm.cshtml")))                            




Jul 26, 2012 at 5:04 PM

Your layout page is not fine at all. Those RenderPage calls are hacky as hell and should not be there. Instead, create User shapes and add them to the zones where you want them. Using "Layout.NameOfTheZone.Add"

Jul 26, 2012 at 5:52 PM

Ok  - all the code above is in the Header.cshtml  which is called into the Layout.chstml - 

WorkContext.Layout.Header.Add(New.Header(), "10"); // social networks / banner and search

So in the header.cshtml swap the Razor RenderPage  call with the WorkContext.Layout.Header.Add?

<!--  RenderPage User Login -->       
REMOVE THIS @RenderPage(Url.Content(Html.ThemePath(WorkContext.CurrentTheme, "/Views/User.cshtml")))       

ADD THIS @*WorkContext.Layout.Header.Add(New.User(), "5");*@

Can we do this within an overidden zone?


Jul 26, 2012 at 6:22 PM

Yes, I think, if I'm following you. Not sure what you mean by "within an overridden zone".

Another trick that may com in handy: you can display a shape inline by doing @Display.NameOfTheShapeInQuestion(SomeModelProperty: SomeValue).

Jul 27, 2012 at 11:43 AM

OK if this terminology is wrong please correct

 I mean the Header zone is being overidden by inserting the Header.cshtml shape/view  this happens in Layout.cshtml when I call

WorkContext.Layout.Header.Add(New.Header(), "10"); 

If now in Header.chstml I try to call in the 

WorkContext.Layout.Header.Add(New.User(), "5"); >>> ERROR - System.InvalidOperationException: Collection was modified; enumeration operation may not execute.


@Display.User(); - WORKS FINE


I just read your article - problem solved, should have found this ages ago - thank you! 

Jul 27, 2012 at 1:50 PM

Well, yes, you can't add shapes to the shape you are in the process of rendering.