N2CMS

Templates

If you have been reading about how content is defined and are wondering how it relates to the presentation you have reached the right page. The first thing to do is to a point out a template by overriding the TemplateUrl property. Like this:

 

Now we've wired the text page to the text.aspx template. There is an url rewriter in N2 that uses the pages name property to map urls to a content item and reading it's template url property to find out which template to use. Lets say we create a page with the name documentation directly below the start page. The url rewriter will rewrite the path /documentation.aspx to the template /text.aspx?item=... By the way, the default template (if you didn't override the TemplateUrl property) is /default.aspx.

The template 

Consider this text.aspx template. The designer:

..and the code-behind file:

To benefit from many of the features in N2 you should inherit the page from a base class: N2.Web.Ui.Page<T> where T would be the type of content item displayed with this template. Like this:

Now we can access the content (data) on the current page through properties of the CurrentPage property. If you aren't interested in any customized properties from CurrentPage you could just as well inherit N2.Web.UI.Page<N2.ContentItem>.

If you are extending the functional templates project you should inherit from N2.Templates.Web.UI.TemplatePage if you want configured master page and styles automatically applied to the page.

Suppose we want to assign this text to this literal control:

We could assign it's text property from code-behind:

Or we could assign it using a the the CurrentPage expression builder:

Assuming we just want to display the text there are a few other options. The Response.Write equivalent:

Or the display control that dynamically outputs the content using the control defined by an attribute on the text property implementing the IDisplayable interface. In this case a Literal will output the content since we used the EditableFreeTextArea attribute:

A few final touches and we've got ourselves a nice little page: