The following is a quick tip for extending the HTML module that comes
included in DotNetNuke 1.0.10.
DotNetNuke comes with some great content tools built right into the package.
The HTML module has the FreeTextBox (FTB) control bundled in with it. The FreeTextBox
control is an open source ASP.Net Web control that you can include in your
projects, more information can be found on the
www.revjon.com Website.
The Problem
For this particular code snippit I wanted to be able to extend the FTB to
make it easier for my content editors to be able to apply DNN styles and insert
links to other tabs within DNN. Another issue was FTB inserts absolute links
when linking to internal documents and not relative links; this is fine if all
you content editing is done on you production system, but in this particular
case we were first building our content on a test server and eventually wanted
to publish it to another domain in production.
The Solution
The solution to this was rather simple thanks to the FTB control providing
several public methods and properties that we can modify. We created a new
method within the EditHTML.ascx.vb control that is located in the ~/DesktopModules/HTML
directory within DNN, and called this method PrepHTMLTextBox. This method will
change some properties for our FTB control and populate the InsertHTML drop down
with links to other tabs that can be inserted into the HTML document simply by
selecting the tab from the drop down box.
The Code
Private Sub PrepHTMLTextbox()
With ftbDesktopText
Dim aryMenuNames As String()
Dim aryMenuList As String()
Dim tmpNames As String
Dim tmpList As String
Dim objArts As New AdminDB
'now call the GetTabs method to get all tabs for this
'portal, then we'll insert them into a string array
'and populate the drop down list of the FTB control.
Dim dr As SqlDataReader = objArts.GetTabs(PortalId)
Dim tmpLink As String
If dr.Read Then
tmpNames = dr("TabName") & ";"
tmpLink = "<a href=""" & IIf(Request.ApplicationPath = "/", _
Request.ApplicationPath, Request.ApplicationPath & "/") & _
"DesktopDefault.aspx?tabid=" & dr("TabID") & """>" & _
dr("TabName") & "</a>"
tmpList = tmpLink & ";"
Do While dr.Read
tmpNames = tmpNames & dr("TabName") & ";"
tmpLink = "<a href=""" & IIf(Request.ApplicationPath = "/", _
Request.ApplicationPath, Request.ApplicationPath & "/") & _
"DesktopDefault.aspx?tabid=" & _
dr("TabID") & """>" & dr("TabName") & "</a>"
tmpList = tmpList & tmpLink & ";"
Loop
tmpNames = Left(tmpNames, Len(tmpNames) - 1)
tmpList = Left(tmpList, Len(tmpList) - 1)
aryMenuNames = Split(tmpNames, ";")
aryMenuList = Split(tmpList, ";")
.InsertHtmlMenuTitle = "Insert Links to Articles"
.InsertHtmlMenuNames = aryMenuNames
.InsertHtmlMenuList = aryMenuList
.RemoveServerNameFromUrls = True
End If
'create another array to populate the styles drop down.
Dim aryStyles As String() = {"Head", "SubHead", "SubSubHead", _
"Normal", "NormalRed", "NormalBold"}
.StyleMenuList = aryStyles
.StyleMenuNames = aryStyles
End With
End Sub
If you look at the code above, you can see what we did here to extend the
control. First we declared some variables to hold our values. Then we called the
method provided by the DNN core framework called "GetTabs" this will return a
Data Reader with the tabs for our particular portal. We then build some href
tags with the returned data which eventually will populate the drop down list.
When someone selects an item from the drop down list, it will insert the html
into the document where they are currently in focus.
After populating the control, we then set the RemoveServerNameFromUrls to
true in order to provide relative linking for our links. And finally we created
a simple array to grab our DNN styles and populate the styles drop down in the
control.
Now once the method is created we just place a call to the method within the
Page_Load event of the EditHTML.ascx.vb class:
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' Obtain PortalSettings from Current Context
Dim _portalSettings As PortalSettings = CType(HttpContext.Current.Items("PortalSettings"), _
PortalSettings)
::
::
::OMITTED CODE
::
End If
End If
End If
End If
PrepHTMLTextbox()
End Sub
Save your changes and then recompile the DNN project. You should now be able
to insert the links to your tabs from within the editor, links are relative, and
styles will be populated.