Content View

From Sense/Net Wiki
Jump to: navigation, search
  •  
  •  
  •  
  •  
  • 100%
  • 6.0
  • Enterprise
  • Community
  • Planned

Overview

Content View
A Content View is an ASP.Net user control (in the form of an .ascx file in the Content Repository) that defines the layout of the HTML block that represents a Content. Content Views are built up of Field Controls - displaying values of Content Fields - embedded into custom HTML layout. When a Portlet is about to render a Content it usually starts with finding and loading the appropriate Content View.

Details

The basic way to display a Content is to use a Content View. The Content View defines the custom HTML to be rendered when the underlying Content is displayed. As a Content is built up of Fields the Content View displays the Content using Field Controls to provide a surface to display/modify the Field values of the Content. The Content View therefore depends on the Content Type of the specific Content (since it defines the Fields of the Content) but a specific Content can be displayed using various Content Views. Content Views are placed in the Content Repository under the folder /Root/Global/contentviews.

Connecting a Content View and a Content

To present a Content using a Content View in practice means that when presenting a Content with a Portlet you may choose a Content View at the appropriate Portlet property to present the Content with. For example when using a Content viewer Portlet you can pick a Content View in the Contentview Path property:

Selecting a Content View in a portlet

Content View modes

A Content can be presented in 3 different modes depending on whether the Content is to be edited, to be browsed or to be created. Different Content Views can be chosen for the Content according to these 3 main scenarios. The name of the Content Views for the 3 modes is set:

  • browse mode: Browse.ascx
  • edit mode: InlineEdit.ascx
  • new mode: InlineNew.ascx

You may however choose a Content View of any name for a Content, the above set names are only used when the Content View is determined automatically for the Content based on the rendering mode. Here is a list of some built-in portlets that render Content in the above set modes:

  • Content viewer Portlet: presents the Content in Browse mode (using Browse.ascx when custom Content View is not provided)
  • Editor Portlet: presents the Content in Edit mode (using InlineEdit.ascx when custom Content View is not provided)
  • Creator Portlet: presents the Content in New mode (using InlineNew.ascx when custom Content View is not provided)

Content View and Content Types

Generally speaking a Content View is a Content Type-dependent control (since Content Types define the Fields of the Content) and therefore the Content Views are organized into a folder structure according to type names. For example Content Views presenting Content of the User Content Type are placed under the folder /Root/Global/contentviews/User. When displaying a user Content and no Content View is provided the appropriate Content View will be resolved and the above path will be probed first.

There is no automatic fallback mechanism for Content Views based on Content Type inheritance. For example defining a Content View for the File Content Type does not define the Content View for its child types, like Image.

Generic Content View

Altough different Content Views can be defined for Content of different Content Types, you don't necessarily have to create new Content Views when you want to present your Content of custom Content Types. You may also notice when browsing the /Root/Global/contentviews base Content View folder that in contrast of the many pre-defined Content Types there are only a few Content Views defined in the Content Repository of the default install. An arbitrary Content can always be presented using the following Generic Content Views:

  • /Root/Global/contentviews/Browse.ascx: generic browse Content View
  • /Root/Global/contentviews/InlineEdit.ascx: generic browse Content View
  • /Root/Global/contentviews/InlineNew.ascx: generic browse Content View

The above Content Views will present any Content by listing all defined Fields of the Content using the default Field Control (the default Field Control for a Field is defined by the Field itself, from code - but can be set with the ControlHint Field Setting property).

Content View path resolution

When chosing a Content View for a Content (for example when picking the Content View path in the correspoing Portlet property of the Content viewer Portlet), you may supply the path of the Content View in the Content Repository - but you may as well leave the corresponding value empty as the path of the best matching Content View will be resolved automatically. The selected Content View depends on the current Skin and the Content Type of the Content. The following article summarizes the Content View path resolution logic:

Creating Content Views

Read the builder documentation for Content Views to learn about creating custom Content Views. Also, here is a short tutorial on this topic:

Command Buttons

In Content Views created to edit Content a button bar is usually shown at the bottom of the layout to enable Content saving and versioning. This is done using the Command Buttons control that displays buttons according to the state of the Content - by state we mean versioning status, versioning mode and whether a new Content is being created or an existing Content is being edited.

Content Views and Field Control modes

Content Views are built up of Field Controls. Field Controls can be rendered in different modes: they either show an enclosing frame with Field Name and Description or not; they either are editable or only browsable. When these modes are not set for the individual Field Controls in the Content View, the Content View itself controls Field Control modes. These settings are defined in code when the Content View is created - generally the host control defines default rendering modes. For example the Content viewer Portlet renders the Content View with its Field Controls set to browse mode and enclosing frames displayed. The Editor Portlet renders the Content View in Edit mode thus all Field Controls are editable.

Other ways of presenting Content

When displaying a Content Collection (multiple Content presented in a single portlet box) Collection Views (ASP.Net control) can be used. Content and Content Collections can also be displayed using XSLT Renderers. Please note, that these techniques are primarily used to display Content (in browse mode) - editing Content can be done with Content Views in the first place.

Example/Tutorials

Related links

References