Cell Template

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


Cell templates

In Sense/Net there are several ways to display more than one content. One of them is using the ContentList Portlet with a List View. The default list view displays content in a grid with a toolbar and separate cells for the field values. The Cell template feature lets you customize the look of these cells.


When you want to customize the HTML markup of a cell in a list view grid, you can do so by creating or modifying the corresponding cell template. Cell templates are simple file content with an .ascx extension. These files are similar to ASP.NET user controls, and are used by the list view generator mechanism.

You can use any HTML markup element or ASP.NET control in the cell template, but be aware that these templates will be used in a databinding scenario, so no inline code fragments will work. The binding context item in this case is the content in the appropriate line of the grid (e.g. a document or a memo).

Please note that currently if you change an existing cell template or create a new one, you have to refresh (save) all the list views in which you want to use the template.

Cell template content

If the list generator mechanism does not find a cell template for a field, it will insert the default value into the view:

<%# Eval("@@bindingName@@") %>

The markup above simply renders the string value of the field into the cell. If you want to change the look of the value you can use any HTML, Javascript or CSS trick:

<span style="color:Red"><%# Eval("@@bindingName@@") %></span>

If you define this markup for the Last modified field, the result will be the following:

DateTime cell template

Cell template variables

You can use the following variables in a cell template. The list view generator mechanism will replace these variables in the template with the appropriate field values.

  • @@bindingName@@ (this is the most common variable that you can use to evaluate the field value as a string)
  • @@fullName@@ (can be used by helper methods)
  • @@fieldName@@ (can be used by helper methods, e.g. SenseNet.Portal.UI.ContentListViews.ListHelper.GetPathList)

Cell template types

The list view generator mechanism will look for the appropriate cell template using a naming convention. See this section to learn more about cell template resolving. There are two types of cell templates that differ only in their names:

  • Cell template for field type: in this case you define a template for a field type, e.g. for DateTime or Reference field (see the Fields page for all fields).
  • Cell template for field name: it is possible to define a more specific template for a particular field name, e.g. CreatedBy or ModificationDate.

Global cell templates

Global cell templates

The simpliest way to customize the html of a cell is to create or modify its global template. The place of these templates is the following folder:

  • /Root/Global/celltemplates

Content List cell templates

Local cell templates

There is a possibility to create different cell templates under content lists. This means that you can define a custom html for a specific list field that exists only in that content list. Local cell templates can be created in the following folder:

  • [...any ContentList path...]/CellTemplates

Cell template resolve algorithm

When you save a list view, the generator mechanism uses the list view markup template (an XSLT file, referenced in the Markup template field of the list view) to generate the list view control. This XSLT contains the call for a helper method that discovers the appropriate cell template for a field (SenseNet.Portal.UI.ContentListViews.ListHelper.RenderCell). The cell template discovery is based on the place of the view. If it is under a content list, the local template folder will be checked, otherwise only the global folder. The probing steps are the following:

  • Local template folder, field name (e.g. ContractDate.ascx)
  • Local template folder, field type (e.g. ReferenceField.ascx)
  • Global template folder, field name (e.g. ModificationDate.ascx)
  • Global template folder, field type (e.g. DateTimeField.ascx)
  • Global template folder, generic template (Generic.ascx)

In case of a Document Library and a datetime field, probing path list looks like the following:

  • /Root/Sites/Default_Site/workspaces/Document/londondocumentworkspace/Document_Library/CellTemplates/ModificationDate.ascx
  • /Root/Sites/Default_Site/workspaces/Document/londondocumentworkspace/Document_Library/CellTemplates/DateTimeField.ascx
  • /Root/Global/celltemplates/ModificationDate.ascx
  • /Root/Global/celltemplates/DateTimeField.ascx
  • /Root/Global/celltemplates/Generic.ascx


Running workflows

The following template is an example on how to display if a workflow is running on the displayed content, or not. You will need to do the following:

  • Add a new Yes/No field to the list, name it WorkflowsRunning, add it to default view, but don't show it in other views.
  • Create a systemfolder under the list, name it celltemplates.
  • Under celltemplates create a User control.ascx, name it WorkflowsRunning.ascx, with the following content:
<%# (SenseNet.Search.ContentQuery.Query(
"+TypeIs:Workflow +WorkflowStatus:1 +RelatedContent:"+
Eval("Id").ToString()+" .AUTOFILTERS:OFF").Count > 0) ? "Workflows running" : "" %>​​​

Content to approve

This template was created to display a link to the content that should be approved when a manager opens an Approve task on the portal.

  • /Root/Global/celltemplates/ContentToApprove.ascx
<sn:ActionList ID="ActionList1" runat='server' ActionName='Browse' ContentPathList='<%# ListHelper.GetPathList(Container.DataItem as SNCR.Content, "@@fieldName@@") %>' UseContentIcon="True" />

Reference field

This template was created to display an action list in case of a reference field.

  • /Root/Global/celltemplates/ReferenceField.ascx
<sn:ActionList runat='server' ActionName='Browse' ContentPathList='<%# ListHelper.GetPathList(Container.DataItem as SNCR.Content, "@@fieldName@@") %>' UseContentIcon="True" />

Related links