Welcome to the navigation

Exercitation aute adipisicing nulla fugiat ullamco commodo aliqua, quis in ut anim deserunt proident, dolore incididunt lorem velit voluptate sunt non et eu minim laboris. Aliquip elit, non dolore excepteur anim eiusmod nisi pariatur, sunt cillum duis ut reprehenderit culpa consequat, ut quis adipisicing ex enim ea qui labore veniam

Yeah, this will be replaced... But please enjoy the search!

Programmatically register a display template in EPiServer Commerce [Snippet]

This is quite simple and follow the general behind the scenes pattern Mediachase use.

Expected result

To programmatically register template references in the commerce manager

Code

// Get all templates
Mediachase.Cms.Dto.TemplateDto templateDto = Mediachase.Cms.Managers.DictionaryManager.GetTemplateDto();

string newTemplateName = "PromotionTemplate";
string newTemplateFriendlyName = "Promotion Template";

// Check if the template exist
if (!templateDto.main_Templates.Any(x => x.Name.Equals(newTemplateName, StringComparison.InvariantCultureIgnoreCase)))
{
    // Create empty template dto
    templateDto = new Mediachase.Cms.Dto.TemplateDto();
    Mediachase.Cms.Dto.TemplateDto.main_TemplatesRow row = null;

    row = templateDto.main_Templates.Newmain_TemplatesRow();
    row.ApplicationId = Mediachase.Cms.CmsConfiguration.Instance.ApplicationId;

    row.Name = newTemplateName;
    row.FriendlyName = newTemplateFriendlyName;
    row.Path = string.Format("~/Templates/DisplayTemplates/{0}.ascx", newTemplateName);
    row.TemplateType = "Entry";
    row.LanguageCode = "en-us";

    if (row.RowState == DataRowState.Detached)
        templateDto.main_Templates.Rows.Add(row);

    // Save any changes
    if (templateDto.HasChanges())
        Mediachase.Cms.Managers.DictionaryManager.SaveTemplateDto(templateDto);
}
Please note that this portal is a BETA site , I will continuously improve all functionality and performance during the coming weeks / the author