DotNetNuke - Header, Content and Footer

2019-04-28 23:00发布

问题:

Is there any way, like one does with WordPress, to create a header.php, theme-file.php and footer.php and then combine them using hooks? It seems crazy to me to still duplicate skin files especially when you need to make minor changes to the content of either a header or footer.

Many thanks

回答1:

A skin is just an ascx control, so you can encapsulate parts of it just like you would any other WebForms view. You can put the header/footer content into their own ascx file, and then just include them in the skin. The only place you'll run into an issue with this is that I don't think DNN supports having panes in separate controls; everything else should be fair game.

You'll want to put them in a separate directory, so that they aren't seen as other skins by DNN.

-MySkin
--Controls
---Header.ascx
---Footer.ascx
--Home.ascx
--Home.doctype.xml
--Interior.ascx
--Interior.doctype.xml

Then, in the skins, include the controls by registering them in the header:

<%@ Register TagPrefix="myskin" TagName="Header" Src="Controls/Header.ascx" %>
<%@ Register TagPrefix="myskin" TagName="Footer" Src="Controls/Footer.ascx" %>

And include it via the control syntax:

<myskin:Header runat="server" />
....
<myskin:Footer runat="server" />

The control won't automatically have access to any context from the skin, so if you need to use SkinPath or PortalId or anything like that, you'll need to pass it through to the control manually. In the control, define a property to receive the value (using a <script runat="server"> section to write code [set the Language attribute in the control to C# for this]):

<script runat="server">
public string SkinPath { get; set; }
</script>

Then pass the value in the skin:

<myskin:Header runat="server" SkinPath="<%# SkinPath %>" />