Dotnetnuke 学习笔记之Skin实现(1) – Default页
刚刚接触DotNetNuke的时候觉得它灵活的模块管理和自定义Skin的特性非常吸引人,于是打算读读他的代码,看看怎么实现的。今天先把Skin部分的学习笔记整理一下贴出来,不当之处,还请大家指正。
Default.aspx页面只有三个控件,其中的Placeholder是装载用户控件用的,对DDN而言,就是装载不同的skin。也就是DDN的Skin就是一个用户控件,他的主要结构就是一个大的表格, 有三列,分别对应Leftpane、ContentPane, RightPane. 所以,装载控件的第一步是Load这个空的skin文件,然后根据数据库中各个Pane应载入的Module分别进行相应的操作。
在Default.aspx.vb, Page_init 子程序中逻辑如下:
(1) 从上下文Context中装载portalSettings (portalSettings在Global.asax中实现初始化并存入HttpContext)
(2) InitializePage() 跳转到相应得Tab并初始化页面信息:例如标题、Copyright、Background、META等等,信息全部从PortalSettings中来。其中设置Background的方法如下:
'set the background image if there is one selected
If Not Me.FindControl("Body") Is Nothing Then
If _portalSettings.BackgroundFile <> "" Then
CType(Me.FindControl("Body"),HtmlGenericControl).Attributes("background")= _portalSettings.UploadDirectory & _portalSettings.BackgroundFile
End If
End If
而其余的信息全部放到全局变量中。
(3) ManageRequest() 处理关联操作(affilates)并记录日志(Log)
(4) 装载Skin: 首先获取设定的skin的路径和名称,一般都是到portalSettings中获取
ctlSkin = LoadSkin("~" & _portalSettings.ActiveTab.SkinPath.Remove(0, Len(Global.ApplicationPath)) & _portalSettings.ActiveTab.SkinSrc)
这里的LoadSkin就是LoadControl:
Private Function LoadSkin(ByVal SkinPath As String) As UserControl
Dim ctlSkin As UserControl
Try
ctlSkin = CType(LoadControl(SkinPath), UserControl)
Catch ex As Exception
' could not load user control
SkinError.Text &= "<center>Could Not Load Skin: " & SkinPath & " Error: " & Server.HtmlEncode(ex.Message) & "</center><br>"
SkinError.Visible = True
End Try
Return ctlSkin
End Function
如果发现指定的Skin无法装载,就会尝试装载default skin.
(5) ManageStyleSheets 动态加载StyleSheet (CSS)
DDN可以定义多个CSS, 如下表,后面的override前面的
1. Modules – styles for custom modules defined in PortalModuleControl.StyleSheet
2. Default – default host level styles – default.css
3. Skin – skin styles – skin.css or skinfilename.css
4. Container – container styles – container.css or containerfilename.css
5. Portal – custom styles defined by portal Administrator – portal.css
(6) 将Skin添加入Palceholder中: SkinPlaceHolder.Controls.Add(ctlSkin)
下一步,将触发skin.vb中的代码,我会在下一篇笔记中详述。
Trackback: http://tb.donews.net/TrackBack.aspx?PostId=171551