Kentico CMS 7.0 Developer's Guide

Managing notification templates

Managing notification templates

Previous topic Next topic Mail us feedback on this topic!  

Managing notification templates

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example creates a notification template.

 

private bool CreateNotificationTemplate()

{

  // Create new notification template object

  NotificationTemplateInfo newTemplate = new NotificationTemplateInfo();

 

  // Set the properties

   newTemplate.TemplateDisplayName = "My new template";

   newTemplate.TemplateName = "MyNewTemplate";

   newTemplate.TemplateSiteID = CMSContext.CurrentSiteID;

 

  // Create the notification template

  NotificationTemplateInfoProvider.SetNotificationTemplateInfo(newTemplate);

 

  return true;

}

 

The following example gets and updates a notification template.

 

private bool GetAndUpdateNotificationTemplate()

{

  // Get the notification template

  NotificationTemplateInfo updateTemplate = NotificationTemplateInfoProvider.GetNotificationTemplateInfo("MyNewTemplate", CMSContext.CurrentSiteID);

  if (updateTemplate != null)

   {

      // Update the property

       updateTemplate.TemplateDisplayName = updateTemplate.TemplateDisplayName.ToLower();

 

      // Update the notification template

      NotificationTemplateInfoProvider.SetNotificationTemplateInfo(updateTemplate);

 

      return true;

   }

 

  return false;

}

 

The following example gets and bulk updates notification templates.

 

private bool GetAndBulkUpdateNotificationTemplates()

{

  // Prepare the parameters

  string where = "TemplateName LIKE N'MyNewTemplate%'";

   where = SqlHelperClass.AddWhereCondition(where, "TemplateSiteID = " + CMSContext.CurrentSiteID, "AND");

 

  // Get the data

  DataSet templates = NotificationTemplateInfoProvider.GetTemplates(where, null);

  if (!DataHelper.DataSourceIsEmpty(templates))

   {

      // Loop through the individual items

      foreach (DataRow templateDr in templates.Tables[0].Rows)

       {

          // Create object from DataRow

          NotificationTemplateInfo modifyTemplate = new NotificationTemplateInfo(templateDr);

 

          // Update the property

           modifyTemplate.TemplateDisplayName = modifyTemplate.TemplateDisplayName.ToUpper();

 

          // Update the notification template

          NotificationTemplateInfoProvider.SetNotificationTemplateInfo(modifyTemplate);

       }

 

      return true;

   }

 

  return false;

}

 

The following example deletes a notification template.

 

private bool DeleteNotificationTemplate()

{

  // Get the notification template

  NotificationTemplateInfo deleteTemplate = NotificationTemplateInfoProvider.GetNotificationTemplateInfo("MyNewTemplate", CMSContext.CurrentSiteID);

 

  // Delete the notification template

  NotificationTemplateInfoProvider.DeleteNotificationTemplateInfo(deleteTemplate);

 

  return (deleteTemplate != null);

}