Page 1 of 1

[solved] Get name of template assigned to page

Posted: Wed Sep 09, 2015 1:37 am
by Cerulean
Is there a method for returning the name of the template that is assigned to a given page ID/alias?

Thanks.

Re: Get name of template assigned to page

Posted: Wed Sep 09, 2015 8:56 pm
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.

Re: Get name of template assigned to page

Posted: Wed Sep 09, 2015 10:28 pm
by Cerulean
Thanks calguy!

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