[SOLVER] Getting a template name through a UDT

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
Guido
Forum Members
Forum Members
Posts: 221
Joined: Sat Aug 29, 2009 3:00 pm

[SOLVER] Getting a template name through a UDT

Post 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.
Guido
Forum Members
Forum Members
Posts: 221
Joined: Sat Aug 29, 2009 3:00 pm

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

Post by Guido »

Should really learn to read at some point. I passed 'id' to the UDT, should have been 'page_id'.
Post Reply

Return to “The Lounge”