This project is read-only.

Controlling the folder for shape templates

Topics: Customizing Orchard
Dec 6, 2011 at 9:19 PM

I've got several shape templates that are going to be similar, but different enough that I want to keep them in separate template files instead of just using one file with a bunch of conditional logic. These templates are for ad-hoc shapes that I'm injecting into a zone of my layout from other shapes. For example, I'm going to have several shape templates like Page1Toolbar.cshtml, Page2Toolbar.cshtml, Page3Toolbar.cshtml, etc. Then from different page templates, I'm going to be doing this:


Where SubNav is a zone in my layout. What I would love to do is to be able to put all of these various toolbar shapes into a Toolbars folder inside my Views folder, instead of having them all in the root of my Views folder where Orchard expects them by default. I'm pretty sure I can do this with an IShapeTableProvider, but I'm not exactly sure how. I would like this to be a convention, so that adding another *Toolbar shape doesn't require a change to the provider. Has anybody done something like this, or have an idea for how to do it?


Dec 6, 2011 at 9:25 PM
Edited Dec 6, 2011 at 9:25 PM

You can do New.Toolbar_Page1Toolbar(), and the template will be Toolbar.Page1Toolbar.cshtml or Toolbar\Page1Toolbar.cshtml.

Dec 6, 2011 at 9:36 PM

OKay, I feel like an idiot, because I knew that but didn't think of it. :-)

However, I don't feel like an idiot because I tried it and it doesn't work. Strange. Seems like it should, but it throws an exception from the DefaultDisplayManager. Seems like it still can't find the template.

Dec 6, 2011 at 9:40 PM

Interesting finding. It does the "." substitution but not the directory path. It will find Views/Toolbar.Page1Toolbar.cshtml but not Views/Toolbar/Page1Toolbar.cshtml.

Obviously, the directory substitution works when creating shapes elsewhere, like from a Driver. Not sure why it doesn't work from this context though.

Dec 6, 2011 at 10:00 PM

I've never really tried it, but I did think it was possible. I tend to stick everything in Views, even though you can end up with a lot of files - you might not be aware but there's some compiler overhead the more folders you have cshtml in.

Dec 6, 2011 at 10:01 PM

(By the way, you could try New.Toolbar_Page1Toolbar(TemplateName:"Toolbar/Page1Toolbar") - I've definitely seen that working.

Dec 6, 2011 at 10:14 PM

Ah, that would seem to make sense too, as that's what you do with editor templates in drivers. But it doesn't work in this context either. Anyway, I think for now I'm just going to make use of the "." substitution which does work. That way at least my templates will be grouped together in the Views folder like


Thanks again.