[solved] Get name of template assigned to page

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am

[solved] Get name of template assigned to page

Post by Cerulean »

Is there a method for returning the name of the template that is assigned to a given page ID/alias?

Thanks.
Last edited by Cerulean on Wed Sep 09, 2015 10:28 pm, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Get name of template assigned to page

Post by calguy1000 »

From the API it's quite simple. You did not provide any context so I will assume you mean from the PHP realm.

Once you have the content object, you can get the design id and the template id.
Once you have the design id, you can load the design object and get it's name.
It is the same with the Template object.

Code: Select all

$hm = CmsApp::get_instance()->GetHierarchyManager();
$node = $hm->sureGetNodeByAlias($the_content_id_or_alias);
$content_obj = $node->GetContent(TRUE);
$template_id = (int) $content_obj->TemplateId();
$design_id = (int) $content_obj->GetPropertyValue('design_id');
$template = CmsLayoutTemplate::load($template_id);
$template_name = $template->get_name();
$design = CmsLayoutDesign::load($design_id);
$design_name = $design->get_name();
of course you must do error checking at each step along the way. The newer CmsLayoutTemplate and CmsLayoutDesign classes will throw exceptions if you try to request an object given invalid data. Some of the older methods will not.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am

Re: Get name of template assigned to page

Post by Cerulean »

Thanks calguy!

After posting here I also found this for earlier versions of CMSMS.
Post Reply

Return to “CMSMS Core”