Thursday, April 1, 2010

DotNetNuke - What is Module Definition?

DNN - What is Module Definition?
What is Module Definition?


A Module must have at least one definition in order to show the default view control in module. More over, Module is collection of module definitions, that contains group of controls (View, Edit, Settings). When a module is installed to the tab, all the definitions are installed to it and default or view controls from all the definition is visible to the tab.

But why do I need it?

When you want to display your module views in different panes!

I don't get you!

Well what will you do if you have a two column layout (skin) and you are asked to show recent posts in the side bar pane and recent comments at the bottom of content pane?

I will create two different modules!

No, that's not a right way to do it! Module definitions are just to do this kind of things. Creating two different module and then creating a module package for both of them and installing them individually is not an efficient way. Logically, your recent posts' view and recent comments are part of your blog module and by installing blog module you will be able to install both of them in any pane of skin you want.

Ok, But I can just add the recent comments at the bottom of my posts in the ascx control, why do I create a separate view for it?


Well, what if client ask you to move it to sidebar? separating the things will allow client to do it him self!



Oh I see! So, I have to create two view controls in the module and just create two separate definitions for both of them.

Right. That's the correct way to do it.

Ok, and what If I want to add "New Post" link to both of the module definitions?

Well, you can create a single edit type of control and you have to add the control's link to both of the view controls and add the edit control to both definitions. But note that if you are using module id this will not work. Module ID for both of them will be different.

[But most of the time, you will not do that in DNN, you will place edit link to the view that is most relevant.]

And what about settings, can I share settings of module between them?

Nop, you cannot share it. installing every definition will create a new module id. and settings are stored by module id so technically, you don't have facility to do this by design. That makes sense, For example, if you want to show unapproved comment's list to the blog owner, and change the setting for that definition, that will not affect the blog list and recent post list.

Conclusion:
You can think module definition as a deploy time helpers, if you want that certain group of view controls should be installed with the installation of module but don't want them to stick to the panes they are installed in, just split your views in more than one view and add as many definitions as you want to allow flexibility.

2 comments:

  1. Nice post. It would be helpful though if you explained how to select the different definitions when it comes to adding modules to a page.

    ReplyDelete
  2. thanks for the comment, good idea, I will try to write a next post for the same

    ReplyDelete

Please add your valuable comments about this post if it helped you. Thanks