API
Version 7.x > API > Programatically choose page template View modes: 
User avatar
Member
Member
renegadefunkman-hotmail - 11/26/2013 6:22:35 PM
   
Programatically choose page template
Hi,

I have a forum where i'd like to show a different page template(with diff webparts) based on whether the user is seeing a thread list or a thread.

For example:
I want to show some forum rules on a thread list, but i want to show post rules as well as top posts and other related information on the post page.

One way to achieve this is to modify all my web parts to be aware of the current page(is it a post or a thread list) but it can become cumbersome given how many web parts we have.

Is there a better way through the api(inheriting from forumviewer) to change the page template that's being loaded?

Thanks,
Cristian


User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 11/29/2013 9:56:23 AM
   
RE:Programatically choose page template
Hello,

Please take a look at the following example code which is used to set a page template for a document:
CMS.DocumentEngine.TreeNode folderNode = CMS.DocumentEngine.TreeNode.New("CMS.MenuItem", tree);

// Get the page template
PageTemplateInfo template = PageTemplateInfoProvider.GetPageTemplateInfo("cms.articlelistwithteasers");

if (template != null)
{
int templateId = template.PageTemplateId;
folderNode.DocumentPageTemplateID = templateId;
}

Best regards,
Martin Danko