This project is read-only.

How to add script block to <head>?

Topics: Customizing Orchard, General, Writing modules, Writing themes
Dec 22, 2011 at 5:14 AM

I'm moving a large amount of MVC3 code into an Orchard module. Mostly it's fine but some of the pages require a javascript <script> block to be rendered to the head. 

I'm using ResourceManifest.cs and Script.Include()/Style.Include() .AtHead() to reference .js and .css resources from the <head> tag, but I don't see a way to do the same thing with a set of inline <script> tags. I'd rather not build my own script management, and my last resort is to define a zone in the <head> and define the contents of that zone from my view. This is similar to what I did in the MVC app before importing it into Orchard -- I used @section {...}. That was annoying because include scripts on the fly with this method wasn't possible from partial views. the Script.Include() and Style.Include() syntax was much nicer to use once I got used to not having Intellisense, but now I still have the problem that I can't add scripts to the <head> on the fly from partial views. 

Dec 25, 2011 at 5:13 AM
@using (Script.Head()) {
    <script language="javascript" type="text/javascript">
        //your script here

have a look here too:
Dec 27, 2011 at 10:51 PM

Thanks -- that did the trick.