Page 1 of 1

Get name of template

Posted: Thu Oct 20, 2016 7:28 pm
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

Re: Get name of template

Posted: Thu Oct 20, 2016 9:30 pm
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?

Re: Get name of template

Posted: Thu Oct 20, 2016 11:06 pm
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.

Re: Get name of template

Posted: Fri Oct 21, 2016 10:33 am
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

Re: Get name of template

Posted: Mon Oct 24, 2016 1:29 pm
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...