Simple Menu Example
To get you started here is a simple example of a custom module that can be inserted into a CMS content page from the editor screen. Its function is to render out some text and also some dynamic content in the form of the current page title.
The ASCX File
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyMenu.ascx.cs" Inherits="MyMenu" %>
<cmsx:FlatMenu ID="menu" runat="server">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li><a href="XLINK_<%# Container.Get("ID") %>_"><%# Container.Get("Title") %></a></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</cmsx:FlatMenu>
The ASCX.cs File
using cmsx;
using cmsx.Common;
[EditorModuleInfo("My Menu", "Testing")]
public partial class MyMenu : System.Web.UI.UserControl
{
[EditorPropertyInfo(true, "Start Page Display", "", false)]
[DefaultValueAttribute("")]
public string PageIDDisplay { get; set; }
[EditorPropertyInfo(true, "Start Page", "SiteTree")]
[DefaultValueAttribute("0")]
public int ParentID { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
menu.ParentID = ParentID;
}
}
The Web.config File
<add tagPrefix="testing" tagName="MyMenu" src="~/modules/MyMenu/MyMenu.ascx"/>
This module allows you to specify a parent page and using this it renders out all the child pages of this parent page. Most of the hard work is performed by the FlatMenu control which simply takes any parent ID and outputs in templated format the child page objects.
The ParentID property is marked with the EditorPropertyInfo attribute which tells the CMS that the property should be presented to the CMS user when the module is inserted onto a page. The 3rd argument "SiteTree" indicates the property needs a page selecting and will be achieved using a site treeview dialog.