Smarty::templateExists PHP Method

templateExists() public method

Check if a template resource exists
public templateExists ( string $resource_name ) : boolean
$resource_name string template name
return boolean status
    public function templateExists($resource_name)
    {
        // create template object
        $save = $this->template_objects;
        $tpl = new $this->template_class($resource_name, $this);
        // check if it does exists
        $result = $tpl->source->exists;
        $this->template_objects = $save;
        return $result;
    }

Usage Example

 public function render($blockName, $moduleName, $controllerName, $actionName, $dataHolder = null, $defaultDir = null)
 {
     $smartyData = $this->smarty->createData($this->smarty);
     if ($dataHolder != null) {
         foreach ($dataHolder as $key => $value) {
             $smartyData->assign($key, $value);
         }
     }
     \org\equinox\utils\debug\DebugBarFactory::add($smartyData->getTemplateVars(), 'Smarty', $blockName);
     $this->smarty->setTemplateDir(ROOT . '/' . $this->templateDir);
     $template = $moduleName . '/' . $controllerName . '/' . $actionName;
     if (!$this->smarty->templateExists($template . '.tpl')) {
         // check the default template
         if ($defaultDir != null) {
             $this->smarty->setTemplateDir($defaultDir);
             $template = $controllerName . '/' . $actionName;
             if (!$this->smarty->templateExists($template . '.tpl')) {
                 throw new \org\equinox\exception\EquinoxException("Cannot find ({$template}.tpl) template in (" . ROOT . '/' . $this->templateDir . ") nor in default directory ({$defaultDir})");
             }
         } else {
             throw new \org\equinox\Exception\EquinoxException("Cannot find ({$template}.tpl) template in (" . $this->smarty->template_dir . ") and no default directory provided");
         }
     }
     $html = $this->smarty->fetch($template . '.tpl', $smartyData);
     \org\equinox\utils\debug\DebugBarFactory::add($html, 'Smarty', $blockName . '_html');
     return $html;
 }
All Usage Examples Of Smarty::templateExists