Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Change a Document Types default template dynamically on creation View modes: 
User avatar
Member
Member
michaeli-newsmax - 7/29/2011 12:30:20 PM
   
Change a Document Types default template dynamically on creation
I wanted to know if it’s possible to change a Document Types default template dynamically while creating it. I do know that I can set the default if I wanted to in the Site Manager.

Examples:

Custom Type :
Cell Phone

Available Templates :
Cell Phone (Default)
Cell Phone with Extended Menu
Cell Phone with Introduction
Cell Phone with Reviews

Let’s say I create a new Cell Phone (iPhone) and I have a Template with an Extended Menu that I want to use for it. I want to make the Content Managers life easier by applying dynamically the Template at the time he creates it and not after. The Custom Type will have a field that lets the Content Manager select to apply the Extended Menu Template to it so he doesn’t have to change it once it’s created. I hope this makes sense.

I know I can use the CustomDataHandler but I don’t know if this is something that could be done.

User avatar
Member
Member
michaeli-newsmax - 7/29/2011 1:28:49 PM
   
RE:Change a Document Types default template dynamically on creation
Thanks to support I managed to get this working.


/// <summary>
/// Fires before inserting tree node to the tree. Performs the additional actions before the tree node is inserted.
/// </summary>
/// <param name="treeNodeObj">TreeNode object to insert to tree</param>
/// <param name="parentNodeId">Parent node ID.</param>
/// <param name="tree">TreeProvider object to use</param>
public override void OnBeforeInsert(object treeNodeObj, int parentNodeId, object tree)
{
// To change a Document Type's default template dynamically when creating it,
// you will need to use the custom tree node handler (OnBeforeInsert method/event).
// Then change there DocumentPageTemplateID of available TreeNode objects to point to
// some page templage (table CMS_PageTemplate -> Column PageTemplateID).
// In this custom tree node handler you can check if the TreeNode object is of some
// specific class (in this case document type) and if so, then change the page template
// for document. You can find DocumentPageTemplateID in the CMS_Document table.
// PageTemplateID PageTemplateDisplayName
// 25 Product multicolumn view

TreeNode treeNode = (TreeNode)treeNodeObj;

if (treeNode.NodeClassName.ToLower() == "cms.cellphone")
{
treeNode.DocumentPageTemplateID = 25;
}
}