Documentation > CMS Template API Library > Asset > CreateTemplateFile(String,Asset)

CreateTemplateFile

Create a template file with the given label in the given location. It can be created in a template only.

public CrownPeak.CMSAPI.Asset CreateTemplateFile(String,Asset)


Returns

A newly created template file.

Parameters

NameDescriptionType
label The label to use System.String
parent The template where the template file is to be created. Must be a template. CrownPeak.CMSAPI.Asset

Code Example

C#

Sample:
string label = "post_input.aspx";	
Asset parent = Asset.Load("/" + asset.AssetPath[0] + "/Project/Templates/Content Page/");
if(parent.IsLoaded)
{
  Asset newTemplateFile = Asset.CreateTemplateFile(label, parent);
  if(newTemplateFile.IsLoaded)
  {
    string strBody = newTemplateFile.Raw["body"];
    strBody += "<" + "%";
    strBody += " asset.Rename(\"Test\"); "; 
    strBody += "%" + ">";
    newTemplateFile.SaveContentField("body", strBody); 
  }
}

Connect with Crownpeak