Hello World Sample
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="HelloWorld.ascx.cs" Inherits="HelloWorld" %>
The ASCX.cs File
using cmsx;
using cmsx.Common;
[EditorModuleInfo("Hello World", "Testing")]
public partial class HelloWorld : System.Web.UI.UserControl
{
[EditorPropertyInfo(true, "Output Count")]
[DefaultValueAttribute("1")]
public int Count { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
string currentPageTitle = Manager.Current.Title;
for (int i = 0; i < Count; i++)
{
Controls.Add(new LiteralControl("<p>Hello from " + currentPageTitle + "!</p>"));
}
}
}
The Web.config file
<add tagPrefix="testing" tagName="HelloWorld" src="~/modules/HelloWorld/HelloWorld.ascx"/>
In the same way that you register an ASP.NET User Control in the web.config you must also register any module you want to use with the CMS.
The code is fairly straight forward, we retrieve the page title of the current page and along with some static text, output it by creating a LiteralControl and adding it to the child controls collection.
This is repeated a configurable number of times and demonstrates how to create properties that can be configured in the CMS editor when the module is inserted into the page.
Rate this:
1 Star
2 Star
3 Star
4 Star
5 Star
1 Rating / 4.0 Average