Thursday, March 11, 2010
Categories
Author:Marian D.Created:7/23/2006 6:35 PM
DotNetNuke

As part of the sequel “How to do simple things in DotNetNuke after you created your first module”, I’ll show you today how to recognize inside your module, when the page is in edit mode and when is in preview mode. 
 
 Me.EditMode property is not enough to show this state of the page. You need also to evaluate the a cookie used to indicate if the page is in preview or not.
  
If Me.EditMode Then
  Dim objPreview As HttpCookie
  objPreview = Request.Cookies("_Tab_Admin_Preview" & PortalSettings.PortalId.ToString)
  If Not objPreview Is Nothing AndAlso CType(objPreview.Value, Boolean) Then
   'the page is in preview mode
   '...
  
Else
   'the page is in edit mode
   '...
  
  End If
End If
  
This is useful, obviously when you want to show different things when the page is in edit mode rather than preview.

This snippet of code shows you how to programmatically create a page (tab) in DotNetNuke 4.x from a template.
It is called from the context of a module, so we have access to some of the main objects of DNN framework, such as PortalSettings.
Few properties are copied from the current active page: TabPermissions, SkinSrc, ContainerSrc. With a little effort you can specify your own values, if these ones are not appropriate.
 
The most important point is the use of the page template. By default, DotNetNuke comes with one template that is adding a HTML module to the main ContentPane. This template is placed in “…\Portals\_default\Templates\ Default.page.template” file. It is a XML file and you can easily change it or clone it to create your own template.
 
        'create new hidden page
        Dim ctrTab As New DotNetNuke.Entities.Tabs.TabController
        Dim objTab As New DotNetNuke.Entities.Tabs.TabInfo
        Dim objActiveTab As DotNetNuke.Entities.Tabs.TabInfo
        objActiveTab = Me.PortalSettings.ActiveTab
        objTab.IsVisible = False
        objTab.PortalID = Me.PortalId
        objTab.TabID = Null.NullInteger
        objTab.PortalID = PortalId
        objTab.TabName = "Page Name"
        objTab.Title = "Page Name"
        objTab.Description = "Description"
        objTab.KeyWords = ""
        'we make it hidden this time
        objTab.IsVisible = False
        objTab.DisableLink = False
        objTab.ParentId = -1
        objTab.IconFile = ""
        objTab.IsDeleted = False
        objTab.Url = "N"
        'get the same permissions as the current active page
        objTab.TabPermissions = objActiveTab.TabPermissions
        'get the same skin as the current active page
        objTab.SkinSrc = objActiveTab.SkinSrc
        objTab.ContainerSrc = objActiveTab.ContainerSrc
        objTab.TabPath = GenerateTabPath(objTab.ParentId, objTab.TabName)
        objTab.StartDate = Null.NullDate
        objTab.EndDate = Null.NullDate
        objTab.PageHeadText = ""
        objTab.TabID = ctrTab.AddTab(objTab)
        'create the page from our template
        Dim xmlDoc As New System.Xml.XmlDocument
        xmlDoc.Load(Server.MapPath(Me.Page.TemplateSourceDirectory & "/Portals/_default/Templates") & _
        "\Default.page.template")
        Dim objPortals As New PortalController
        objPortals.ParsePanes(xmlDoc.SelectSingleNode("//portal/tabs/tab/panes"), _
                              objTab.PortalID, objTab.TabID, PortalTemplateModuleAction.Ignore, New Hashtable)
 
I will conclude that creating pages programmatically is not complicated in DotNetNuke, and can be useful in the process of custom module creation, when we want to save the admin user few extra steps.

 

The problem I have with dnn module installer/packager is that I cannot pack files with same name that reside in different locations of your module subfolders.

Read More »

Four steps for migrating HTML module source code from DNN 3 to DNN 4

Read More »

Privacy Statement  |  Terms Of Use
Copyright 2008 by dumitrascu.NET