Monday, June 20, 2011

Creating a DNN skin object

Hi All,

Below is a demonstration of how to create a DNN skin object. I’ll demonstrate this by creating a skin object that will display total number of users in your dnn site. Here we go:
Ø      Create a new project with template type “DotNetNuke Compiled Module”. Some other project type like class library project might also do but this one is easiest to start with.
Ø      I created a new project with name “CurrentUsersInfoSkinObject” and then cleaned it up by deleting all of the files from it, except below:
o       ViewCurrentUsersInfoSkinObject.ascx
o       ViewCurrentUsersInfoSkinObject.ascx.cs
o       App_LocalResources/ ViewCurrentUsersInfoSkinObject.ascx.resx
o       CurrentUsersInfoSkinObject.dnn
Ø      SkinObjects inherit from SkinObjectBase so change line
o       partial class ViewCurrentUsersInfoSkinObject : PortalModulebase
o       to
o       partial class ViewCurrentUsersInfoSkinObject : SkinObjectBase
Ø      Now add a literal control to ascx page, like below:
o       <asp:Literal ID="litUsersCount" runat="server" Mode="PassThrough" EnableViewState="false">asp:Literal>
o       pay attention on Mode and EnableViewState property.
Ø      Add one line to the resource file as below. This will serve as the base string to be shown in skin object.

Ø      Now place three lines of code in code behind file of view control.
o       string templateText = Localization.GetString("UsersCountDisplayTemplate", Localization.GetResourceFile(this, _myFileName));
o       templateText = templateText.Replace("[USERSCOUNT]", UserController.GetUsers(PortalSettings.PortalId).Count.ToString());
o       litUsersCount.Text = templateText;
o       In above three lines, first line reads resource file to get source string. Second line replaces placeholder [USERCOUNT] with number of users and set literal control to show this value.
Ø      Now just build this project, place dll in bin folder of your DNN installation.
Ø      Now place ascx and resource file in desktop modules folder, I placed these as shown in below image.

Ø      Now go to your dnn skin file. For me it was at,
Portals\_default\Skins\MinimalExtropy\ index leftmenu 1024.ascx
Ø      Add a line to register your newly added control. Like

<%@ Register TagPrefix="dnn" TagName="ViewCurrentUsersCount" src="~/DesktopModules/SkinObjects/ViewCurrentUsersInfoSkinObject.ascx" %>
Ø       Now add a line to place it at your desired place in skin. I placed it along with login control, like below:
<dnn:ViewCurrentUsersCount runat="server" id="UserCount" />
Ø      That’s all that you need to do to see your first skin object working.

No comments:

Post a Comment