More in this section
Blogs RSS feed

Mapping External Template in Sitefinity with the API

by Stanislav Velikov
The ability to map external templates to different Sitefinity widgets is performed in the backend UI from Administration->Settings->Advanced->Controls->View Map.

To perform the mapping of a template trough code refer to the sample below:
var configManager = ConfigManager.GetManager();
            var viewMap = configManager.GetSection<ControlsConfig>();
            ConfigProperty property;
            var viewMapValue = viewMap.Properties.TryGetValue("viewMap", out property);
            string[][] bag = new string[4][];
            bag[0] = new string[2] { "Value", "Telerik.Sitefinity.Web.UI.NavigationControls.SiteMapNavigations.SiteMapNavigationTabStrip, Telerik.Sitefinity" };
            bag[1] = new string[2] { "Key", "HostType" };
            bag[2] = new string[2] { "Value", "~/CustomNavigationTemplate.ascx" };
            bag[3] = new string[2] { "Key", "LayoutTemplatePath" };
            var ConfigSectionItems = new ConfigSectionItems();
            ConfigSectionItems.SaveBatchConfigSection(bag, "ViewMap_0,controlsConfig_0", "", "", null, "New", "");
The highlighted part of the code contains the required values for mapping a template, those are the host control type and a path to the mapped template.

Layout Template: ~/CustomNavigationTemplate.ascx

Additional approaches in mapping external templates are described in this blog post.


Leave a comment
  1. Hardy Aug 14, 2013
    Thank you, Stanislav. What is the meaning of the argument "ViewMap_0,controlsConfig_0" in the last line? Do we have to use this literally every time we create a view map in code or do we have to increment the counter each time ("ViewMap_1,controlsConfig_1","ViewMap_2,controlsConfig_2" etc.)?
  2. Federico Aug 22, 2013
    Couldn't think a better way to do it

    Leave a comment