This project is read-only.

Where is Model object documented

Topics: Customizing Orchard, Writing modules, Writing themes
Nov 30, 2012 at 1:14 AM
Edited Nov 30, 2012 at 1:22 AM

I am new to Orchard. The themes that I've looked at all seem to have a lot of references to an object called "Model". For example most versions of content.cshtml seem to have lines like these:


This object appears to contain all of the good stuff you need to build a page. What I can't seem to figure out is where it's documented. Help!

Nov 30, 2012 at 5:26 PM

This is a fundamental MVC concept: the views render what's being handed to them through the view Model object. It's not the same object in all views of course, it's whatever the controller or driver prepared for that specific view to render. If you want to track back where the object is defined, you have to find the controller or driver that is responsible for getting this view to render.

Nov 30, 2012 at 10:09 PM

I am familiar with the Model-View-Controller concept, but that's not really the issue at hand.  I don't want to track back to where the Model object is defined... How would someone just trying to edit layout.cshtml even go about doing that anyway? This isn't something you should have to look at the Orchard source code to figure out.  I can't imagine that Orchard's designers intended for one to be a fairly experienced programmer just to do something as basic as creating or modifying a theme.

To be clear, I am aware that this is a dynamic object which can have different properties at different times. However, this is a relatively deterministic context.  Every time Orchard processes layout.cshtml or content.cshtml (for example) the Model object is going to have certain properties.  If it didn't always have the "content" property available, for example, every theme would require a bunch of extra code to test for the existence of any property before using it.

So, when I'm editing my layout.cshtml file, what properties are always going to be available?  Surely there is some documentation, somewhere, that lists and defines these properties?

My experience with Orchard so far is that it's got a lot of potential, but it seems like the documentation has been an afterthought. If I google the "wpdb object for Wordpress" I get a ton of useful results.  If I google the "model object for orchard", not so much.  I know WP is older and much more common place, but the first results for that search are their own documentation, and I would expect the same for Orchard but it ain't happening.

Dec 1, 2012 at 6:41 AM

Right, you didn't mention that you were looking at Content and Layout.

In most views, Model is a dynamic object, which opens up some interesting possibilities, such as starting to use an object before it has actually been created. In the case of layout and content, most of the things you can see hanging off Model are zones, which are target containers for widgets in the case of layout, and for parts (through placement) in the case of content. What's important here is the names of those zones, because that's what widgets and placement will use. So the object model here is not fixed at all, it's actually entirely up to the template author.

Does this help?

As for the documentation, like everything in Orchard, it's open source. Please feel free to contribute and improve things.