This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
[This post is part of the developer's manual preview published on this blog. You can find temporary TOC here.]
[This article requires Sitefinity 3.6 hotfix to be installed]
Before we go into the code, let us examine on the following two screenshots how should our solution look like - once it’s done.
And, once the user clicks on the Content Reporting link in the command panel, we’d expect him to see the following screen.
So, our task was to extend Generic Content module with a new View for content reporting, provide the command for accessing this new view, make sure that the breadcrumb is working correctly and make sure that when user clicks on the command on the left side our View is seamlessly loaded as if it was a natural part of Generic Content module. What a mouthful!
First thing we are going to do is create a new View. As it was described in this article, we can create Views either from User Controls or Custom Controls. For the purpose of this article, we are going to create a View from a User Control. Here are step-by-step instructions on what you need to do to create the View we are going to use.
using System; |
using Telerik.Cms.Web.UI; |
using Telerik.Cms.Engine.WebControls.Admin; |
public partial class Views_ContentReportingView : ViewModeUserControl<GenericControlPanel> |
{ |
protected void Page_Load(object sender, EventArgs e) |
{ |
} |
} |
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ContentReportingView.ascx.cs" |
Inherits="Views_ContentReportingView" %> |
<div id="divWorkArea" runat="server" class="workArea insert"> |
<div class="mainForm"> |
<h3>Authoring statistics</h3> |
<fieldset class="set"> |
<ol class="setIn"> |
<li> |
<strong>Items count</strong>: 88 |
</li> |
<li> |
<strong>Words count</strong>: 22.547 |
</li> |
</ol> |
</fieldset> |
<div class="bottom"><div><!-- --></div></div> |
</div> |
</div> |
*** NOTE ***
While the code-behind file and the markup for this sample are intentionally simple, you can make them complex and functional as much as you need. Don’t forget though, that a View should do only one single thing. If you would to develop a complex reporting functionality, you would be best off adding Subviews to the View we’ve built above, thus creating hierarchy. For more on this concept consult this article.
*** END NOTE ***
Views collection of the viewSettings element represents the subviews of the View defined in the hostType property of the viewSettings element. Views collection supports add, remove and clear methods as it is customary with the xml configurations and collections. To achieve our taks of injecting a new View in the Generic Content module we will put following declaration in the Controls Config file:
<!--Root view of the Generic Content module.--> |
<viewSettings hostType="Telerik.Cms.Engine.WebControls.Admin.GenericControlPanel"> |
<views> |
<add name="ContentReporting" |
virtualPath="~/Views/ContentReportingView.ascx" |
title="Content reporting" |
description="From here you can explore the authoring statistics of content." /> |
</views> |
</viewSettings> |
At this moment our task has been completed and you can test it.
*** IMPORTANT ***
Every time you modify ControlsConfig file it is necessary to restart the application in order for the changes to be applied. While there are numerous ways to restart an application, here are few handy ones - you can restart the IIS server, resave web.config file (e.g. open web.config file, press space, press backspace, save config.file), resave global.asax file (e.g. open global.asax file, press space, press backspace, save global.asax file)…
*** END IMPORTANT ***
What is left to do is to explain what exactly we have done in the Controls Config file that had made all this work. We will analyze this process step-by-step:
Subscribe to get all the news, info and tutorials you need to build better business apps and sites