The content you're reading is getting on in years
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]
In versions prior to Sitefinity 3.6 there was a convention that for each new provider (see this article on provider model if you need a refresher) one would create a new folder in ~/Sitefinity/ControlTemplates and ~/Sitefinity/Admin/ControlTemplates folders and name it after the provider name. Sitefinity would then automatically go to these folders and find the appropriate templates based on the provider name.
In Sitefinity 3.6, since the templates have been embedded, this concept is not applicable anymore.
Before we delve into the specifics, let us first examine why would one want to have different templates for different providers. While you will find many scenarios that require such customization, a good and common example to explain this principle is TagsList control.
TagsList control is part of the Generic Content module and its fully qualified name is:
Telerik.Cms.Engine.WebControls.Tags.TagsList
However, since all Generic Content based modules support tagging, such as Blogs or News, we will probably be reusing this control for different purposes (on one page we will display list of blog tags, on another list of news tags). Following this thought comes the requirement that the template for TagsList control when used for Blogs is different than when used with News.
Luckily, new Controls Config file can handle this with utmost simplicity.
<!--Provides user interface for displaying the list of tags for the content items.--> |
<viewSettings hostType="Telerik.Cms.Engine.WebControls.Tags.TagsList" |
layoutTemplatePath="~/Sitefinity/ControlTemplates/Generic_Content/TagsList.ascx" /> |
<!--Provides user interface for displaying the list of tags for the content items.--> |
<viewSettings hostType="Telerik.Cms.Engine.WebControls.Tags.TagsList" layoutTemplatePath="~/Sitefinity/ControlTemplates/Generic_Content/TagsList.ascx"> |
<additionalTemplates> |
<add key="Blogs" |
layoutTemplatePath="~/Sitefinity/ControlTemplates/Blogs/TagsList.ascx" /> |
</additionalTemplates> |
</viewSettings> |
*** 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 ***
*** NOTE ***
If you map to an external template that ends with the .ascx extension, you will be using standard ASP.NET template parser which means you will also need to provide localization file in the App_LocalResources file. Resources files are also part of the package that comes with ExternalTemplates.zip file.
*** END NOTE
A question may come to one’s mind, what happens if we specify a provider name for which we haven’t defined additional template. Namely, if template for provider has not be mapped, Sitefinity will gracefully fall back to the default mapping defined in the viewSettings elements as "~/Sitefinity/ControlTemplates/Generic_Content/TagsList.ascx".
What is left to demonstrate is how to map embedded templates of controls that have multiple templates differently based on the provider name. While, you may feel slight dizziness from the previous sentence, in fact the approach is rather simple and straightforward.
Let us take ListDisplay control for an example. ListDisplay control has seven different templates, based on the mode in which you wish to display the list. Our first step is to map the embedded templates to external ones. In order to do so, we will paste following declaration between the viewMap nodes of our Controls Config file:
<viewSettings hostType="Telerik.Lists.WebControls.ListDisplay"> |
<additionalTemplates> |
<!--Simple list--> |
<add key="SimpleListTemplatePath" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists/SimpleListView.ascx" /> |
<!--Expanded list--> |
<add key="ExpandedListTemplatePath" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists/ExpandedListView.ascx" /> |
<!--Expandable list--> |
<add key="ExpandableListTemplatePath" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists/ExpandableListView.ascx" /> |
<!--Anchor list--> |
<add key="AnchorListTemplatePath" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists/AnchorListView.ascx" /> |
<!--Page list--> |
<add key="PageListTemplatePath" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists/PageListView.ascx" /> |
<!--Simple Rotating list--> |
<add key="RotatingListsSimpleTemplatePath" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists/RotatingListsSimpleView.ascx" /> |
<!--Expanded Rotating list--> |
<add key="RotatingListsExpandedTemplatePath" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists/RotatingListsExpandedView.ascx" /> |
</additionalTemplates> |
</viewSettings> |
<viewSettings hostType="Telerik.Lists.WebControls.ListDisplay"> |
<additionalTemplates> |
<!--Simple list--> |
<add key="SimpleListTemplatePath" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists/SimpleListView.ascx" /> |
<!--Expanded list--> |
<add key="ExpandedListTemplatePath" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists/ExpandedListView.ascx" /> |
<!--Expandable list--> |
<add key="ExpandableListTemplatePath" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists/ExpandableListView.ascx" /> |
<!--Anchor list--> |
<add key="AnchorListTemplatePath" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists/AnchorListView.ascx" /> |
<!--Page list--> |
<add key="PageListTemplatePath" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists/PageListView.ascx" /> |
<!--Simple Rotating list--> |
<add key="RotatingListsSimpleTemplatePath" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists/RotatingListsSimpleView.ascx" /> |
<!--Expanded Rotating list--> |
<add key="RotatingListsExpandedTemplatePath" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists/RotatingListsExpandedView.ascx" /> |
<!--Simple list--> |
<add key="SimpleListTemplatePath|Lists1" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists1/SimpleListView.ascx" /> |
<!--Expanded list--> |
<add key="ExpandedListTemplatePath|Lists1" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists1/ExpandedListView.ascx" /> |
<!--Expandable list--> |
<add key="ExpandableListTemplatePath|Lists1" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists1/ExpandableListView.ascx" /> |
<!--Anchor list--> |
<add key="AnchorListTemplatePath|Lists1" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists1/AnchorListView.ascx" /> |
<!--Page list--> |
<add key="PageListTemplatePath|Lists1" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists1/PageListView.ascx" /> |
<!--Simple Rotating list--> |
<add key="RotatingListsSimpleTemplatePath|Lists1" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists1/RotatingListsSimpleView.ascx" /> |
<!--Expanded Rotating list--> |
<add key="RotatingListsExpandedTemplatePath|Lists1" layoutTemplatePath="~/Sitefinity/ControlTemplates/Lists1/RotatingListsExpandedView.ascx" /> |
</additionalTemplates> |
</viewSettings> |
View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.