This project is read-only.

Adding content to head

Topics: Customizing Orchard, Writing themes
May 18, 2011 at 7:44 PM

Is there any way to add arbitrary content to the <head> tag?  For example, say I want to create some dynamic css or javascript in a shape alternate and place it in the header.  I'm using Script.Include and Style.Include to reference files, but if you wanted to put an arbitrary block of html in the head, is there any way to do that?  

May 18, 2011 at 8:42 PM

You should be able to add shapes to the "Head" zone on the layout. Do you know how to get hold of layout?

May 18, 2011 at 9:57 PM

I got it to work.  Had some fun playing around with the shapefactory.  Just curious, where is the code located when you call New.{ViewName}()?  I tried to use that by passing in the args, it didn't work, so I ended up doing this instead b/c I couldn't find the source:

var argsDict = new Dictionary<string, object> {
    { "Arg1", Arg1Val },
    { "Arg2", Arg2Val }   
var args = ClaySharp.Implementation.Arguments.From(argsDict.Values, argsDict.Keys);
WorkContext.Layout.Head.Add(ShapeFactory.Create("ViewName", args)); 

//this doesn't work

May 18, 2011 at 10:15 PM

You should be able to do just ...Add(New.MyViewName(Arg1: Arg1Val, Arg2: Arg2Val));

Aug 3, 2011 at 5:16 AM

Here's what I did, seems to work well but Bertrand let me know if this is wrong...

1. In Theme.txt add a Zone called Head
2. Bring in the Document.cshtml from TheThemeMachine and add @Display(Model.Head) in the <head> tag somewhere.  I put it just above the </head>
3. In the Views folder add a Shape Template called Widget-Head.cshtml with the following code:


Now you can add an HTML widget to the Head zone containing your markup of choice and it will be unencumbered by the default article tags.

I hope this helps!

Aug 4, 2011 at 12:32 AM

That sounds pretty nice, yes.