Kentico CMS 6.0 Developer's Guide

Managing web templates

Managing web templates

Previous topic Next topic Mail us feedback on this topic!  

Managing web 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 web template.

 

private bool CreateWebTemplate()

{

  // Create new web template object

  WebTemplateInfo newTemplate = new WebTemplateInfo();

 

  // Set the properties

   newTemplate.WebTemplateDisplayName = "My new template";

   newTemplate.WebTemplateName = "MyNewTemplate";

   newTemplate.WebTemplateDescription = "This is web template created by API Exapmle";

   newTemplate.WebTemplateFileName = "~\\App_Data\\Templates\\MyNewTemplate";

   newTemplate.WebTemplateLicenses = "F;S;B;N;C;P;R;E;U;";

   newTemplate.WebTemplatePackages = "ECM;SCN;ADV;DOC;";

 

  // Set the web template order

  DataSet webTemplates = WebTemplateInfoProvider.GetWebTemplates(null, null, 0, "WebTemplateID", false);

  if (!DataHelper.DataSourceIsEmpty(webTemplates))

   {

       newTemplate.WebTemplateOrder = webTemplates.Tables[0].Rows.Count + 1;

   }

  else

   {

       newTemplate.WebTemplateOrder = 1;

   }

 

  // Save the web template

  WebTemplateInfoProvider.SetWebTemplateInfo(newTemplate);

 

  return true;

}

 

The following example gets and updates the web template created by the API example above.

 

private bool GetAndUpdateWebTemplate()

{

  // Get the web template

  WebTemplateInfo updateTemplate = WebTemplateInfoProvider.GetWebTemplateInfo("MyNewTemplate");

  if (updateTemplate != null)

   {

      // Update the properties

       updateTemplate.WebTemplateDisplayName = updateTemplate.WebTemplateDisplayName.ToLower();

 

      // Save the changes

      WebTemplateInfoProvider.SetWebTemplateInfo(updateTemplate);

 

      return true;

   }

 

  return false;

}

 

The following example moves the web template created by the first example on this page down by one position in the order in which the templates are listed when creating a new website from a web template.

 

private bool GetAndMoveWebTemplateDown()

{

  // Get the web template

  WebTemplateInfo moveDownTemplate = WebTemplateInfoProvider.GetWebTemplateInfo("MyNewTemplate");

  if (moveDownTemplate != null)

   {

      // Move template down

      WebTemplateInfoProvider.MoveTemplateDown(moveDownTemplate.WebTemplateId);

 

      return true;

   }

 

  return false;

}

 

The following example moves the web template created by the first example on this page up by one position in the order in which the templates are listed when creating a new website from a web template.

 

private bool GetAndMoveWebTemplateUp()

{

  // Get the web template

  WebTemplateInfo moveUpTemplate = WebTemplateInfoProvider.GetWebTemplateInfo("MyNewTemplate");

  if (moveUpTemplate != null)

   {

      // Move template up

      WebTemplateInfoProvider.MoveTemplateUp(moveUpTemplate.WebTemplateId);

 

      return true;

   }

 

  return false;

}

 

The following example gets multiple web templates based on a WHERE condition and bulk updates them.

 

private bool GetAndBulkUpdateWebTemplates()

{

  // Prepare the parameters

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

 

  // Get the data

  DataSet templates = WebTemplateInfoProvider.GetWebTemplates(where, null);

  if (!DataHelper.DataSourceIsEmpty(templates))

   {

      // Loop through the individual items

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

       {

          // Create object from DataRow

          WebTemplateInfo modifyTemplate = new WebTemplateInfo(templateDr);

 

          // Update the properties

           modifyTemplate.WebTemplateDisplayName = modifyTemplate.WebTemplateDisplayName.ToUpper();

 

          // Save the changes

          WebTemplateInfoProvider.SetWebTemplateInfo(modifyTemplate);

       }

 

      return true;

   }

 

  return false;

}

 

The following example deletes the web template created by the first example on this page.

 

private bool DeleteWebTemplate()

{

  // Get the web template

  WebTemplateInfo deleteTemplate = WebTemplateInfoProvider.GetWebTemplateInfo("MyNewTemplate");

 

  // Delete the web template

  WebTemplateInfoProvider.DeleteWebTemplateInfo(deleteTemplate);

 

  return (deleteTemplate != null);

}