Injecting HTML into the head

Jan 22, 2011 at 2:41 PM

I want to put some HTML into the head of the pages using my theme. I need to add a conditional comment stylesheet to make my new design work in IE 6 and 7. It's either that or use a CSS hack, which I'd rather not do.

I tried copying document.cshtml into my template but this stopped Html.Title from working for some reason and all my titles went blank.

Is there a way to add HTML to the head section from my theme without creating my own document.cshtml


Richard Garside.

Jan 22, 2011 at 3:51 PM

You can use a filter, which is called during each request, to add the corresponding HTML in the zone you want. There is an example in Bertrand's module to add meta tags.

And in case you didn't know, your theme can have some code like any other module. You just need to create a project for your theme, and it will be compiled also.

Jan 22, 2011 at 3:55 PM

Thanks. I managed to find a CSS fix, but this is still good to know.

Jan 22, 2011 at 10:20 PM

Just found this. Not tried it but think it would have worked nicely for my conditional IE style sheet:

RegisterLink(new LinkEntry { Condition = "lte IE 6", Rel = "stylesheet", Type="text/css", Href = Href("../Styles/ie6.css")}.AddAttribute("media", "screen, projection"));

Jan 27, 2011 at 9:23 PM

@RichardGarside Great find that. Also you need to add;

@using Orchard.UI.Resources;