Skip Navigation Links

JosephGuadagno.NET

Creating a new Sitefinity generic content module

Sponsors

Side Page Content

Sponsors


Loading...The search is starting ...

Initial Draft

created on 7/27/2008 at 12:39 PM by JosephGuadagno

Number of Views

1000

Description

 

So, I heard that the Sitefinity application had this generic content module that was pretty easy to  use to create your own module with. Why do you need to create a new generic content based module you ask?  There a few answers to that question.  I created a new generic content based module because I wanted to track all of the discounts that were offered to the Southeast Valley .NET user group and since free time is a something I do not have lately, it was an easy choice.  You might also want to leverage the existing Sitefinity generic content module because you do not have any development resources available to.  As the name implies it is generic, so generic in fact, it is used by the blog feature, news feature and events feature.

So, I heard that the Sitefinity application had this generic content module that was pretty easy to  use to create your own module with. Why do you need to create a new generic content based module you ask?  There a few answers to that question.  I created a new generic content based module because I wanted to track all of the discounts that were offered to the Southeast Valley .NET user group and since free time is a something I do not have lately, it was an easy choice.  You might also want to leverage the existing Sitefinity generic content module because you do not have any development resources available to.  As the name implies it is generic, so generic in fact, it is used by the blog feature, news feature and events feature.

After a week’s worth of digging into the code and documentation, I was successful. So that you do not have to go through the pain, I will lay out the instructions for you.  This guide will require virtually no coding, just a little HTML markup and some web.config changes.

There are few steps involved with creating a new copy of the generic module.  The first step is to BACKUP your web.config file and Sitefinity project, just to be safe. Here is a list of other steps:

 Getting Started

Modify the web.config file

Create the new admin section

Create the new control templates

Add the data

Create the Sitefinity page to display the content

Summary

Document Conventions

Throughout this document you will see the text <ModuleName>. Whenever you see this text you should replace the <ModuleName> with the new name of your module. For example, I created a discount module and whenever I saw <ModuleName> I replaced it with Discount.

Getting Started

There are two bugs in Sitefinity 3.2 Service Pack 2 hot fix 1616 that cause potential problems with using multiple generic control providers and the ContentView control.  Here are the posted fixes for them.

Multiple Providers Fix

This bug does not allow for you to select multiple generic content providers.

To fix this issue, check out the Sitefinity knowledgebase article titled “Adding a custom provider for Generic Content

Setting for ContentView controls are reset fix

To fix this issue, check out the Sitefinity knowledgebase article titled “Settings applied to the Content View based controls are reset

Resource Files

Sitefinity is built on top of the .NET framework, and this coding technology can localize text properties (and other attributes, such as tooltips) Within an ASP.NET page, you will see the string <%$Resources:SearchItemsBy %>. This code tells the ASP.NET engine to get the resource file text in the key SearchItemsBy. This language is based on the page’s locale..  If this text was on the ControlPanelInsert.ascx control, ASP.NET would look within the ControlPanelInsert.ascx.resx file, unless you had localized versions then it would look in ControlPanelInsert.ascx.<locale>.resx.

For more information, please read “Walkthrough: Using Resources for Localization with ASP.NET ” from MSDN.

Keep this in mind while editing your Sitefinity controls later on.

ContentView Control Overview

The ContentView control in Sitefinity does most of the work for displaying generic content on a control or page. The ContentView control displays data on the web control by “looking” for control names that match the Meta field names within the provider.  If you have a Meta field called Product,” then the ContentView control will look for a control on the page with the name “Product” and populate the control with the value of the Meta field.

When the ContentView control sees a control with one of these names it will populate them with special functions.

Control name

Purpose

fullContent1

This will be used to create a hyperlink to the details or “SingleItem” version of this content item.

fullContent2

This is the same as fullContent1.

content

This will be used to display your generic content.

CommentsLink

This will be used to create a hyperlink to view the comments of the content

CommentsCount

This will be used to display the total number of comments on this content.

Category

This will be used to display the category of the content. If this is a hyperlink control, the contentview control, will place a hyperlink on the page that will allow you to view all of the content classified in that category.

Tags

For this you will need an ASP.NET Repeater control and the content view control will place the tags used for that content

Bookmarks

For this you will need an ASP.NET Repeater control and the content view control will place the tags used for that content

 

The ContentView control has two properties under the appearance section that tell it what control to display on the web page when you are in List mode or Single Item mode. These two properties are ItemListTemplatePath and SingleItemTemplatePath, respectively.

Modify the web.config file

Before you begin, BACKUP your web.config. The smallest error or unclosed angle bracket will cause your Sitefinity application to stop working.

Add the new provider

Locate the section in your web.cofig file that is titled cmsProvider. It looks something like this

<cmsEngine defaultProvider="Generic_Content">

Copy the element (section) whose name is “Generic_Content”. It should look something like this

<add name="Generic_Content" urlRewriteFormat="[Publication_Date]/[Title].aspx" urlDateTimeFormat="yy-MM-dd" urlWhitespaceChar="_" visible="True" defaultMetaField="Name" securityProviderName="" allowLocalization="False" allowVersioning="True" allowWorkflow="False" allowComments="false" commentsModeration="true" versioningProviderName="" connectionStringName="GenericContentConnection" type="Telerik.Cms.Engine.Data.Providers.DefaultProvider, Telerik.Cms.Engine.Data"/>

Paste this element onto the next line of the web config.

Change the following attributes.

Attribute

Value

name

<ModuleName>

urlRewriteFormat

The way you would like your urls to look.

defaultMetaField

The name of the default meta field.

Note: This must match a value in the meta field that you create later; otherwise you will get a difficult to debug “The given key is not present in the dictionary” exception.

The urlRewriteFormat field can comprise of any of your Meta field names.  It my case, I created the following.

urlRewriteFormat="/[Company_Name]/[Product].aspx"

All of the other fields you are free to do with as you choose.  Her e is the sample Discount provider.

<add name="Discounts" urlRewriteFormat="/[Company_Name]/[Product].aspx" urlDateTimeFormat="yy-MM-dd" urlWhitespaceChar="_" visible="True" applicationName="/Discounts" defaultMetaField="Product" securityProviderName="" allowLocalization="False" allowVersioning="True" allowWorkflow="False" allowComments="false" commentsModeration="true" versioningProviderName="" connectionStringName="GenericContentConnection" type="Telerik.Cms.Engine.Data.Providers.DefaultProvider, Telerik.Cms.Engine.Data"/>

Add the new Meta fields

Further down in the web.config file, you should find a <metaFields> element, add Meta keys for each field for your new module.  For the discount module, here is what I added:

<add key="Discounts.Product" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue=""/>

<add key="Discounts.Company_Name" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue=""/>

<add key="Discounts.Company_Url" valueType="ShortText" visible="True" searchable="False" sortable="False" defaultValue=""/>

<add key="Discounts.Product_Logo_Url" valueType="ShortText" visible="True" searchable="False" sortable="True" defaultValue=""/>

<add key="Discounts.Discount" valueType="ShortText" visible="True" searchable="False" sortable="False" defaultValue=""/>

<add key="Discounts.Discount_Code" valueType="ShortText" visible="True" searchable="False" sortable="True" defaultValue=""/>

<add key="Discounts.Category" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue=""/>

<add key="Discounts.Author" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue="Joseph Guadagno"/>

Please note that the name of the module and the word before the period must match the module name. For the Discounts Module provider I discussed, the name should be Discounts as shown below this sentence:

<add name="Discounts" urlRewriteFormat…>

 The important part is for each property/field you want you need to add a line. You will notice the format is <add key=”<ModuleName>.PropertyName”.  For more information on the attributes, check out the Sitefinity developer’s documentation at http://www.sitefinity.com/help/developer-manual/telerik.cms.engine-telerik.cms.engine.metainfo_members.html.

Save your web.config and this completes all necessary changes to the file.

Create your new admin section

Create the folder structure

So you can interface with the Discounts Module, you will now need to create the template files by following these steps:

  1. Open the Windows Explorer (or within Visual Studio). 
  2. Navigate to your website’s root directory.
  3. Go to ~/Sitefinity/Admin/ControlTemplates folder.
  4. Select the Generic_Content folder and paste it into the ~/Sitefinity/Admin/ControlTemplates directory.
  5. Rename that folder to <ModuleName>. In my example, I renamed it to Discounts.

File List

Old name

New Name

App_LocalResources

All of the application resource files are found here. These files contain most notably the text properties for all of the controls on the template.  There should be one .resx for each .ascx file.  This is how .NET allows you to create localized versions of your applications.

CategoriesField.ascx

Provides a drop down list of categories to choose from.

CategoriesManagement.ascx

Provides the ability to add, remove and modify categories that are available to this generic content.

CategoriesSelector.ascx

A control to select the categories to filter your records by.

CommandPanel.ascx

This control is what is displayed on the left hand side of the Sitefinity administration console.  You should not need to modify this.

CommentsEdit.ascx

A control that provides the ability to edit the comments of your generic content.

CommentsList.ascx

A control that lists the comments for your generic content.

CommentsView.ascx

A control that displays the individual comment of your generic content from the comments list control.

ContentSelector.ascx

This control provides a means to let you select generic content.

ContentVersionView.aspx

This is the control that will display the version history when you click on the version tab.

ControlPanelEdit.ascx

This is the admin control that allows you to edit your generic content.

ControlPanelInsert.ascx

This is the admin control that allows you to insert your generic content.

ControlPanelList.ascx

This is the admin control that displays the generic content available.

ControlPanelPermissions.ascx

This control provides the security controls for your generic content.

Design

Folder for the designer templates. I do not think these are used yet.

EditorTemplate.ascx

Not sure of purpose.  Not sure of use.

NewContentDialog.ascx

When you are creating page and you drag the Generic Content Module onto it, this is the dialog when you click “Share this Content”

SelectContentDialog.ascx

Same idea as above, but this is when you click on “Select Shared Content”

TagEditor.ascx

This control allows you to edit an individual tag

TagsManagement.ascx

This control allows you to edit the tags available for your content.

 

Modify the admin files

There are three files that you are going to want to modify to accommodate your new Meta fields. They are ControlPanelList.ascx, ControlPanelInsert.ascx, and ControlPanelEdit.ascx.  I listed them in the order that they should be modified for testing.

ControlPanelList.ascx

As mentioned previously, the ControlPanelList.ascx control is used to display the generic content in the admin panel. Of the three controls, the List control is the least likely to need modification. This control has two divs called “ToolsAll” and “workArea,” which break up the workspace for listing the generic content.

ToolsAll contains the createNewButton, which allows you to create a new generic content item and the searchInputs section which allows you to search for generic content. The choices for the search criteria depend on whether you make the Meta data “searchable” in the web.config file. Here is an example:

<add key="Discounts.Product" searchable="True"

The div named “workArea” is broken up into three sections; gridTitle which provides the title for the grid, the GridView1 which will display the grid of generic content items, and an ASP.NET PlaceHolder control named emptyWindow, which displays text when there are no content items in this provider.

If you would like to add a new provider with additional Meta fields, then you would need to add additional columns to GridView1 because this grid displays the meta fields.  These additional columns would help you narrow down the generic content that you want to modify. 

<asp:GridView ID="GridView1"

To add a column to the grid control looks the <Columns> element, use the sample below this sentence:

<asp:BoundField DataField="Company_Name" SortExpression="Company_Name" HeaderText="<%$Resources:Company_Name %>" HeaderStyle-CssClass="GridHeader_SiteFinity" />                           

<asp:BoundField DataField="Author" SortExpression="Author" HeaderText="<%$Resources:Author %>" HeaderStyle-CssClass="GridHeader_SiteFinity" />

 

In this sample, I removed the Description field because I am not using it. I added a Company_Name column because this was a new meta field I added to the web.config file. Be sure to remove any unused Meta data fields or else you will get a runtime exception.

ControlPanelList.ascx.resx

Here are the contents of the resource file with some modifications.

Name

Value

AllContentItems

All <ModuleName>

Author

Author

CheckGenericContentFAQ

Check <ModuleName> FAQs

Company_Name

Company name

CreateNewItem

Create a <ModuleName>

CreateYourFirstContent

Create your first <ModuleName>

CreateYourFirstContentTooltip

Click to create your <ModuleName>

Delete

Delete

Description

Description

Edit

Edit