The sole purpose of this control is to display content in a list-details manner. In Sitefinity, most of the functionality derives from our Generic Content module that is used by content writers to add content to their websites. So far, you had to use the Generic Content toolbox control to display a single piece of content onto your pages, but you did not have a control which gives you the ability to display a list of such pieces of information onto your page.
Now, you'll definitely ask “Why would I ever need to display a list of content items with your new control when I have my Lists toolbox control and my Lists module which serves this purpose quite well, doesn’t it?”
Well, yeah it works wonderfully, but there are times when people ask “How do I extend the Lists module?” and we have to admit “Well, actually, you can’t.”
And then the almighty Content View toolbox control appears on the stage! It is built to be extendable; it is built to be used in different situations; it is built to work out-of-the-box and with some slight modifications to serve your purpose in many possible cases.
2. What do I need to set up to make it work? It looks kind of odd when I drop it on my page!
Well, it is still an ugly duckling, but it works! And it works totally out-of-the-box! It makes all the items added to the Generic Content module appear in a list-details manner.
Now you can make some modifications through its properties to make it behave the way you like:
Display Mode (the most important property):
• Auto mode
This mode is selected by default. When it is selected, the control first displays a list of content items and each item can have a link to a mode where it is the only one displayed on the page. All this is handled by the control and you don’t have to worry about it! Here are some examples where you can need this: blogs, news, galleries with thumbnails and full-sized images, job listings, real estate properties for sale, etc.
• Item List mode
When this mode is selected, the control displays only a list of content items. You won’t have the ability to go and see the specific item in the page. Here are some examples where you would need this: list of files for download; short news page; page with short advertisements; gallery of full-sized images, etc.
• Single Item mode
When this mode is selected, the control displays only one content item on the page. In order to make it work, you will additionally need to add the tag by setting the SelectedItemId property. Where would you need this if you have the Generic Content control? Decide for yourself!
• Tags mode
When this mode is selected, the control displays a list of content items tagged by a specific tag. You get the functionality to go and view the single item separately if you need it out-of-the-box. In order to make this mode work, you must add the tag by setting the TagID property. Here are some examples where you would need this: you have a bigger content base and you need to display only a handful of it. The solution is tag some of the items with a specific tag and use this mode.
• Categories mode
Works exactly like Tags mode, except that you must to set the CategoryID property. The examples are almost the same as with the tags, just that categorization works like folders do.
AllowLinksToPrevNextItem
This property allows you to have links to the previous and next items from the list when viewing an item separately.
ItemListUrl and SingleItemUrl
These properties allow you to have the List and Details views to be displayed on 2 different pages. This is how to do it:
1. Let’s say we have a page called Page1.aspx and we have a Content View control dropped on it. We want to make this page handle the display of the list of content items. We need to set the SingleItemUrl property to point to the URL of the page (Page2.aspx) where another Content View control will handle the display of the full content of only 1 content item.
2. Page2.aspx, as we said, needs to have the Content View control dropped on it and it will display the full content of only 1 content item. We need to set the ItemListUrl to point to the page (Page1.aspx) with the list of content items so that the user can navigate back to it if needed.
ParentIDs
Many times your content resides in some sort of an abstract container, i.e. blog posts in blogs, images in galleries, etc. This property allows you to set delimited IDs of these containers so that the control displays content items from them only.
AllowComments
This property gives you the ability to control whether comments can be added to your content items. This is a really neat functionality which has many real-world applications: blog comments, comments about a picture in your gallery, etc.
AllowCommentsModeration
This property gives you the ability to add comments moderation to your content. You will need to create administrative UI to do this but you have it publicly working out-of-the-box!
Various *Key properties (TagItemKey, ContentProviderKey, CategoryKey , ContentItemKey, PageKey)
These properties are used as QueryString key names. All of them have default values. In the controls that derive from Content View, you will need to add different default values from the ones in Content View so that your control and Content View control can work on the same page and don’t have QueryString troubles. Also, when you add 2 instances of one and the same control deriving from Content View, you will need to set these properties from the Control Designer for the very same reason.
ProviderName
This property is one of the really important ones. When you derive a control from Content View, you will need to give it a default value so that later you can use your control without the need to set this property. But if you explicitly want to set your control to work with a provider different than the default one, you will need to set this property to the Provider’s name.
DateFrom
This property is currently not implemented but it is here to provide you with the ability to add a starting date which will filter out all older content items.
SortExpression
This property gives you the ability to sort the list of content items the way you like. It is set by default to “Publication_Date DESC” which will sort your content items by their publication date in descending order (from old publication dates to new ones).
AllowPaging
This property gives you the ability to allow your users to page through the items or not. By default it is set to true.
ItemsPerPage
This property gives you the ability to set the number of content items to display on a page when paging is allowed. By default it is set to 10.
SummarySettings
This property provides the functionality to set the display format of a content item summary. There are two options: to provide several variables that define the summary, or to provide a meta field.
• Summary Variables
For this option, the property includes four variables: type of unit (words/sentences/paragraphs); unit number (an integer); boolean of whether HTML tags should be cleared (false if clearing should not occur); exceptions for the previous variable ("{x}" where x is the tag that should be excluded from the previous setting). For example, if the following is saved in the SummarySettings property: "Words; 20; False; {img}". This means that there should be 20 Words (Words; 20), that HTML tags should not be cleared (False) except for the image ones ({img}).
• Meta Fields
If this option is selected, only a meta field should be provided for this property. It should be placed in square brackets. For example, the following could be the input in this property field: [Summary].
PageTitleMode
There are three modes for setting the page title:
• Append
When this mode is selected, the title of the current item will be appended to the page title.
• DoNotSet
When this mode is selected, there will be no change to the page title.
• Replace
When this mode is selected, the page title will be replaced by the title of the current item.
PageTitleMetaFields
This property lists the meta fields to include in the page title. For example, they could be the following: Title, Theme, Author.
PageTitleFormatString
This property sets the string format of the page title by defining the meta fields to include in the title and their order. The meta fields are the ones set in the PageTitleMetaFields property. The order depends on the one in which the meta fields have been input. The format is the following: "> {x}" where {x} is replaced by the meta field placed on position x. For example, if the following meta fields are saved in the PageTitleMetaFields property: Title, Theme, Author. If " > {0},{2}" is saved in the PageTitleFormatString property, the meta fields will be the following: Title, Author.
We will demonstrate how to extend Content View control by showing you one of our popular controls, the Blog Posts control.
Here are all the methods and properties that are overridden to extend the functionality of the Content View control in order to serve its purpose – display blog posts:
Various *Key properties (TagItemKey, ContentProviderKey, CategoryKey , ContentItemKey)
All these have been overridden to provide values different than the default ones of the Content View control.
CreateFilter()
Overridden method to create a filter by which the list of blog posts is filtered. By default it creates a filter which filters out all blog posts whose publication date is in the future. This is how you can actually draft posts in Sitefinity. But when the user has set the DateFrom property, it uses it to display blog posts for 1 month starting from the DateFrom date.
GetDefaultContentProvider()
Overridden method to return the default blogs data provider.
GetItemUrl()
Overridden method to use administration-managed blog posts page which will be used if there is no SingleItemUrl set by the user. If there is no such page set in the admin, then we will use the default implementation in Content View.
SetItemMetadata()
Overridden method to set various controls in the template by using the blog post metadata.
SetSingleItemContent()
Overridden method to use the administration-managed abilities to allow comments and comments moderation.