Get name of template

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
spcherub
Power Poster
Power Poster
Posts: 402
Joined: Fri Jun 06, 2008 5:54 pm

Get name of template

Post by spcherub »

Is there a way for to get the name of the template of the current page?
For instance, my Navigator template looks something like this:

Code: Select all

{if isset($nodes)}
  {foreach $nodes as $node}
      <tr
      {fetch file="{$node->url}"}
      </tr>
  {/foreach}
{/if}
I'd like to be able to add some conditional logic based on the name of the template of the node (inside the foreach loop). I'm wondering if there's a way to get this information from either within the core or using a module like CGSimpleSmarty (which I've already looked into).

TIA,
Sanjay
spcherub
Power Poster
Power Poster
Posts: 402
Joined: Fri Jun 06, 2008 5:54 pm

Re: Get name of template

Post by spcherub »

I did some more searching and was able to write a UDT based on Calguy's response to a similar question earlier:

Code: Select all

$page_id = !empty($params['page_id']) ? $params['page_id'] : null;
$hm = CmsApp::get_instance()->GetHierarchyManager();
$node = $hm->sureGetNodeByAlias($page_id);
$content_obj = $node->GetContent(TRUE);
$template_id = (int) $content_obj->TemplateId();
$template = CmsLayoutTemplate::load($template_id);
$template_name = $template->get_name();
return $template_name;
Question: Is there another way that does not require the use of a UDT in 2.x?
chandra

Re: Get name of template

Post by chandra »

Have you tried to place this at the top of your page template?

Code: Select all

{assign var='root_template' value=$smarty.template scope='global'}
Now {$root_template} should be available for your conditions in Navigator module.
spcherub
Power Poster
Power Poster
Posts: 402
Joined: Fri Jun 06, 2008 5:54 pm

Re: Get name of template

Post by spcherub »

Thanks for that tip on how to get the template name for the current page. I did not realize that it is contained in the $smarty object. In my case however, I need to be able to get the name of the templates of other pages from within the Navigator code, so any tips to that end will be appreciated.

On a related note, is there a list of all the information contained with the $smarty object (especially CMSMS related)?

Thanks,
Sanjay
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1967
Joined: Mon Jan 29, 2007 4:47 pm

Re: Get name of template

Post by Jo Morg »

spcherub wrote:On a related note, is there a list of all the information contained with the $smarty object (especially CMSMS related)?
http://www.smarty.net/docs/en/language.variables.tpl
CMSMS doesn't add properties to the $smarty object...
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Post Reply

Return to “CMSMS Core”