Page 1 of 1

[SOLVER] Getting a template name through a UDT

Posted: Mon Jan 18, 2016 11:37 am
by Guido
In the 1.x series, I used this UDT:

Code: Select all

$page_id = !empty($params['page_id']) ? $params['page_id'] : null;
$assign = !empty($params['assign']) ? $params['assign'] : null;
 
 if (!empty($page_id)) {
  $contentOps = cmsms()->getContentOperations();
  $templateOps = cmsms()->getTemplateOperations();
 if (!empty($contentOps) && !empty($templateOps)) {
   $content = $contentOps->LoadContentFromId($page_id);
      if (!empty($content)) {
    $templateID = $content->templateId();
    if (!empty($templateID)) {
     $template = $templateOps->LoadTemplateByID($templateID);
     if (!empty($template)) {
      if (!empty($assign)) $smarty->assign($assign, $template->name);
      else return $template->name;
     }
    } 
   }
  }
 }
 
 return false;
To get the template name (I want to make sure in a certain case only the pages from a certain template are shown). Now this doesn't work anymore. I turned on error reporting in the index.php file and got this:

Code: Select all

Notice:  Undefined index: template_name in MY_SERVER/public_html/cms_sandbox/tmp/templates_c/80842882a27ae59cf6219909d3b41240ec259d78.tpl_body.31.php on line 56
Line 56 reads:

Code: Select all

<?php echo print_r($_smarty_tpl->tpl_vars['template_name']->value);?>
Is there a problem with the scope of the smarty var, or is there something else wrong about the UDT? I'm not experienced enough with the CMSMS methods to identify yet I'm afraid.

Re: [SOLVER] Getting a template name through a UDT

Posted: Mon Jan 18, 2016 12:08 pm
by Guido
Should really learn to read at some point. I passed 'id' to the UDT, should have been 'page_id'.