How do I add content part data to Document.cshtml?

Jan 6, 2011 at 3:21 PM
Edited Jan 6, 2011 at 3:25 PM

This would be for something like adding meta keywords/description to a page.
I've got everything ready to go, but I can't figure out how to add the content part data to what seems to be the highest parent shape. I've overriden Document.cshtml (I copied the one from Orchard.Core into my module) and can just type html content in there and have it on the page that has this part.
I've tried multiple variations of adding something like this into my Document.cshtml:


    <meta name="keywords" content="@Model.MetaKeywords"/> <!-- this where I want my content part data -->
    <meta name="description" content="@Model.MetaDescription" />
    <meta charset="utf-8" />


and this in my handler:


OnGetDisplayShape<MetaPart>((ctx, p) => {
			ctx.Shape.MetaKeywords = p.Keywords;
			ctx.Shape.MetaDescription = p.Description;


but no dice. Also, by copying over the whole Document.cshtml, I'm afraid I'm overriding more than I should. For instance, if I was going to package and share this module using this method, I think it could break other themes if they have their own Document.cshtml, correct?

Jan 6, 2011 at 4:44 PM
Edited Jan 6, 2011 at 5:09 PM

OK. I figured this part out. I got an instance of ResourceManager through IWorkContextAccessor, then used the SetMeta() method to add meta keywords and description.

Now, I need to add a script block. I've gotten as far as getting an empty script block into the <head/> tag, but the script text isn't showing up.


OnLoading<MetaPart>((ctx, p) => {
			ResourceManager.SetMeta(new MetaEntry() {
				Name = "keywords",
				Content = "keyword test"

			ResourceDefinition def = ResourceManager.DynamicResources.DefineScript("Test");
			def.TagBuilder.InnerHtml = "alert('hello');"; //this does not render. I've also tried setInnerText() with the same string.
			def.SetAttribute("name", "test-script");



My script block gets rendered as this:


<script type="text/javascript" name="test-script"></script>


Jan 6, 2011 at 6:53 PM

DefineScript is setting up a resource for inclusion as a url. To include just static script, you can use ResourceManager.RegisterHeadScript or RegisterFootScript. It just takes the script you want as a parameter (which should include the script tag itself).

Jan 6, 2011 at 7:08 PM
Edited Jan 6, 2011 at 7:13 PM

Any idea how I can restrict the script to only be added to the head tag of a  part with that content part? This is also adding it in the admin section (when listing a summary of content items).