N2CMS

How is content used on a page

Until now we've learned how we can define content items and make their properties editable through the edit interface. Another important aspect in any CMS are the templates. The HTML that surrounds our content data and gives it a nice appearance.

Our only template: default.aspx

  • Content items (those we examined on step 2) have a property TemplateUrl which says what template will be used to display that item.
  • Since we were using default.sapx as template we didn't need to change anything.
  • Examine the GalleryItem. Did you notice we're inheriting N2.Web.UI.Page? Since we are inheriting this base class we have some nice options when it comes to getting our content. Read on...

Generic page base class

  • The page base class is generic so we can define exactly which content class we're working with on this type of page.
  • This means we can access properties on our content object in a type-safe manner and get all the goodies of intellisense.

Intellisense...

  • That Text property is defined in our custom TextPage class.

Accessing properties in the page aspx

  • In the aspx file we can retrieve various properties (sometimes I call these details) from the content bearing class. The Title property is defined in the base class N2.ContentItem (that and a few others is in common to all content classes).

The CurrentItem expression builder

  • Another way to get content from our class is by using a custom expression builder. The expression's syntax looks just like getting a resource or connection string: <%$ CurrentItem:Text %> The bolded part is the content we're assigning to the literal in this case.