Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Default template for a new Event View modes: 
User avatar
Member
Member
William Awaji - 10/5/2011 1:35:08 PM
   
Default template for a new Event
I want to set a default template for each new event that i create. I just set on the Site Manager->Document Types->Event->Default page template = my template.

This resolved my problem, but create another one. I have 2 sites on the kentico. When i edit this setting, each new event in both sites are create with my template.

I don´t want to create a CUSTOM Document Type.


Can one help me?


User avatar
Member
Member
kentico_michal - 10/16/2011 6:24:08 AM
   
RE:Default template for a new Event
Hello,

You will need to use custom code to set the template only on one of your sites. You can either modify the EditForm page which generates the a new document interface. You would need to change this line of code (~\CMSModules\Content\CMSDesk\Edit\Edit.aspx.cs -> line 257):

// Set default template ID
formElem.DefaultPageTemplateID = templateId > 0 ? templateId : ci.ClassDefaultPageTemplateID;


From my point of view a better way how to accomplish it is to use the CustomTreeNodeHandler class. In general, the custom handler (CustomDataHandler, CustomTreeNodeHandler etc.) gives you ability to execute custom code when some CMS event occurs. You can use for example the OnAfterInsert event that gets executed after a new document is inserted to the database to change the TreeNode.DocumentPageTemplateID property to an appropriate value based on the current site.

If you want more information about the CustomTreeNodeHandler class and how to add it to your project, please visit following links: Event handling overview, Treenode handler

Best regards,
Michal Legen

User avatar
Member
Member
Leandro Brito - 10/18/2011 7:35:27 AM
   
RE:Default template for a new Event
I'm using the method "OnBeforeInsert" on "CustomEventHandler" project to define the "DocumentPageTemplateID" and I need get the ID of template using some query to search by "PageTemplateCodeName".

How to do this code in C#? What namespaces, classes and methods I need to implent?

Thanks

User avatar
Member
Member
kentico_michal - 10/19/2011 4:23:52 AM
   
RE:Default template for a new Event
Hello,

You can use the PageTemplateInfoProvider.GetPageTemplateInfo method. Please take a look at following code snippet:


using CMS.PortalEngine;

PageTemplateInfo pti = PageTemplateInfoProvider.GetPageTemplateInfo(string pageTemplateName);
if (pti != null)
{
// here you can access pti.PageTemplateId
}


I hope this will help you.

Best regards,
Michal Legen

User avatar
Member
Member
Leandro Brito - 10/19/2011 6:22:53 AM
   
RE:Default template for a new Event
Works fine, thank you.