MCMS Add placeholders to all templates

private void Page_Load(object sender, System.EventArgs e)

{

CmsApplicationContext context = new CmsApplicationContext();

context.AuthenticateAsUser("WinNT://INTELLIA/andrstev", ""

,PublishingMode.Update);

TemplateGallery templateRoot = context.RootTemplateGallery;

TemplateWalker(templateRoot);

context.Dispose();

}

private void TemplateWalker(TemplateGallery gallery)

{

foreach(Template template in gallery.Templates)

{

AssurePlaceholder(template,"MetaKeywords");

AssurePlaceholder(template,"MetaDescription");

Response.Write("<HR>");

}

foreach(TemplateGallery childGAllery in gallery.TemplateGalleries)

{

TemplateWalker(childGAllery);

}

}

private void AssurePlaceholder(Template template,string name)

{

if(template.PlaceholderDefinitions[name] == null)

{

HtmlPlaceholderDefinition definition = template.CreatePlaceholderDefinition(typeof(HtmlPlaceholderDefinition)) as HtmlPlaceholderDefinition;

definition.Name = name;

definition.AllowAttachments= false;

definition.AllowHyperlinks = false;

definition.AllowImages = false;

definition.AllowLineBreaks = false;

definition.Formatting = HtmlPlaceholderDefinition.SourceFormatting.NoFormatting;

definition.Description ="Meta tag content";

definition.MustUseResourceGallery = true;

Response.Write("Added::");

Response.Write(template.Path);

Response.Write("::");

Response.Write(name);

Response.Write("<BR>");

}

}

No Comments