Creating a template

So far we've defined a content class, created the database schema added the root node. To make the site complete we need to display the content. Consider the following asp.net template (aspx):

An empty template

It's an empty aspx page, and the code behind file is also empty:

An empty code behind file

Extending the template

To more easily output our content we can inherit from a base class in N2. The generic part of the base class is useful since it allows us to easily access the properties we added to the content class. If a baseclass isn't an option - or you don't like base classes - you can use the N2.Web.UI.IContentTemplate interface which is injected with the current content item. You can also retrieve the data through the API:s.

Extending a base class

Now we can use several way to output or content or bind it to web controls on the page. The example shows two ways to output content. Through the Response.Write equivalent <%= "text" %> and through the display control. Since we decorated the Text property with a EditableFreeTextArea the content will be dynamically added with a Literal control.

Output content on a page

Finally a quick look at the page as people visiting the site will see it. You can of course use the data and the web controls in your existing aspx pages.

A simple page displayed