Page title in created module

Topics: General
Sep 26, 2011 at 9:31 PM

I replicated the tutorial for creating a "HelloWorld" module ( I am using this as a base to develop a more complicated module. 

In the cshtml file for the NFL module I created, I have this simple code:

<!DOCTYPE html>

<html lang="en">
        <meta charset="utf-8" />
        <title>NFL Fantasy Projections</title>
<p>NFL player data...</p>

As in the tutorial, I have the module set so it uses my site theme. But I can't figure out why the page title won't show up on the created page. The page title that shows up in the browser is just "FantasyAcademy" (name of site), not the page title I had set "NFL Fantasy Projections".

I'm guessing that since it can't read in the page title, this is also the reason why the zone-sub-page-title section does not show up as well (the blue bar with "Contact Us").


If anyone has any ideas about this, I would really appreciate it.



Sep 26, 2011 at 10:30 PM

The view should not have all the html chrome: this is going to be added by document.cshtml, which is the wrapper for layout.cshtml. The view that you return from the action is going to be rendered in the Content zone of layout, so it should have no html, head or body tag.

Sep 27, 2011 at 12:56 AM
Edited Sep 27, 2011 at 3:46 AM

Thank you for your response. I apologize if I'm a bit slow at this, I'm fairly new to programming.

I have taken out the html code from the cshtml file.  I was able to get a page title to show up at the top of the browser by adding the layout.title line to the view. I also found I can get the blue bar to display by adding the workcontext line (copied from the content.cshtml page) to the modules's view cshtml file, although it displays without text formatting. The cshtml file is now:


@{ Layout.Title = T("NFL Player Projections").ToString(); 
	WorkContext.Layout.SubPageTitle.Add(Layout.Title, "10");}
<p>@T("NFL players database...")</p>


However, I still can't figure out how to trigger the blue bar naturally without manually calling the subpagetitle. 


Thank you for the help,


Sep 27, 2011 at 5:49 PM

After looking at this more, I just need help getting the formatting correct. 

My module's cshtml view:

@{ Layout.Title = T("NFL Player Projections").ToString(); 
	WorkContext.Layout.SubPageTitle.Add("Page Title", "10");}
<p>@T("NFL players database...")</p>

Using the shape tracing feature, I was able to pinpoint that in order to have proper formatting, it needs an <h1> tag in the zone-sub-page-title. The workcontext line in the code above sends "Page Title" as plain text, but I can't figure out how to give it h1 formatting. Any ideas?



Sep 27, 2011 at 7:15 PM

Instead of adding a plain string, you can add a shape: WorkContext.Layout.SubPageTitle.Add(New.SubPageTitleShape(Subtitle: "Page Title"), "10");} and then create a SubPageTitleShape.cshtml file in your theme's views folder with <h1>@Model.Subtitle</h1>.

Sep 27, 2011 at 7:29 PM

Awesome. Thank you very much. Works perfectly.

Nov 10, 2011 at 10:45 AM
Edited Nov 10, 2011 at 10:47 AM

What if I need to have that sub page title on all site pages, and it should include some context information?

For example: I would like to have the same sub page title on page where all content marked with specific tag is displayed. Sub page title should contain that tag, it should looks like "Contents tagged with MyTag", where MyTag is the value of Orchard.Tags.ViewModels.TagsSearchViewModel.TagName

Is there any way to do that in my theme, instead of adding following code directly to Orchard.Tags/Views/Home/Search.cshtml?


WorkContext.Layout.SubPageTitle.Add(New.MySubPageTitleShape(Title: @T("Contents tagged with {0}", Model.TagName)), "10");


Nov 10, 2011 at 7:14 PM

Yes, by doing it in your theme, you should be able to do it in your theme ;) You can override any template in your theme.

Nov 13, 2011 at 12:30 PM

I would be happy to override it in theme :) I'm not sure I understand how to do that properly. Orchard.Tags/Views/Home/Search.cshtml is not the template for content item, or part, or field. 

I would like to customize it, for example add sub page title, change layout and render some additional information. How I can override Orchard.Tags/Views/Home/Search.cshtml?

First option that I found is to create URL alternate. I added Zone-Content-url-tags.cshtml in Views folder of my theme and copied code from Orchard.Tags/Views/Home/Search.cshtml

In this case I get exception: The model item passed into the dictionary is of type 'IShapeProxyef648e7c2e9f4d54873fd8be3a64e0e7', but this dictionary requires a model item of type 'Orchard.Tags.ViewModels.TagsSearchViewModel'.

Other option is to copy Orchard.Tags/Views/Home/Search.cshtml in Views folder of my theme and update this view. It works, but what if I need to customize other module view with the same name or what if I alreay have Search.cshtml in my theme?

What is the correct way to override Orchard.Tags/Views/Home/Search.cshtml?

I apologize if my questions are not really related to current topic.

Nov 14, 2011 at 9:56 AM

It's not a shape or a content item, it's just a plain MVC view. When you're override MVC views you need to use the module name in your views folder - so you copy it to [Your.Module]/Views/Orchard.Tags/Home/Search.cshtml

Nov 18, 2011 at 5:45 PM

Exactly, that's what I need. Thank you!