Help with injecting shape templates

Topics: Customizing Orchard, Writing modules
Dec 31, 2012 at 12:02 AM
Edited Dec 31, 2012 at 6:16 AM

I'm trying to understand injecting shape templates a little better.

I've seen several examples of injecting ad hoc shapes, but I'm still fuzzy about a few things.

So, from the Theme Machine theme, there is this line:

WorkContext.Layout.Footer.Add(New.BadgeOfHonor(), "5");

It creates an ad hoc BadgeOfHonor shape template. This makes sense because elsewhere in the theme there is a BadgeOfHonor.cshtml view.

However, in the same layout, there is this line:

WorkContext.Layout.User.Add(New.User(), "10");

There is no User.cshtml so it's getting it some other way (from Core/Shapes I presume). How does it know where to get it?

What got me wondering how this works is that I'm trying to inject the view for the QuickLogOn module.  I've tried:


I thought this might work given that there's a part called QuickLogOnWidget.cshtml defined in the module. No luck though. Gives a "Shape type QuickLogOnWidget not found". I've even defined a Part.QuickLogOnWidget.cshtml in my theme hoping that it would work, but no love there either.

I figured that if I knew more about how creating ad hoc shape templates work, I could figure out how to load the QuickLogOnWidget.

Any ideas?

Jan 3, 2013 at 7:09 AM

Any clever folks out there?

I'm supposing that over New Years might not have been the best time to post this question.  :-)

Jan 3, 2013 at 9:01 AM

Just name your file 'QuickLogOnWidget.cshtml' in the 'Views' folder of your theme, not Part.QuickLogOnWidget.cshtml.

Jan 5, 2013 at 6:27 PM

That works for simple templates, but how do I pass the QuickLogOnWidget Model in to the view?

When I try this the Model is missing. I think in this case we're just injecting a simple view, not necessarily injecting the actual widget.

Maybe injecting a shape template isn't what I need. Is there a way to inject a widget within layout.cshtml.

What do you think?

Jan 6, 2013 at 1:01 AM

To add a widget to a zone you should use the Widget section in the admin dashboard. Add the widget to a layer that suits your needs (Default = all pages).

Jan 6, 2013 at 2:25 AM

Yes, if I was simply adding a widget to my site I would do it that way. However, I am trying to inject a widget template programmatically in my *Theme*. This would be in the Layout.cshtml file.