Exemple #1
0
 /**
  * do rendering
  * @params array data
  * @params string template_name
  * @params int templateSwitch
  */
 function do_render($data, $template_name, $templateSwitch = 1, $templateVersion = '')
 {
     $this->_errors = array();
     $tpl_path = self::getTplPath($this->_type, $template_name, $templateSwitch, $templateVersion);
     if (!$this->_smarty->templateExists($tpl_path)) {
         $tpl_not_found = true;
         //首页兼容,如果找不到首页,就用baidu模板下的首页
         if ($templateSwitch == 2) {
             $template_name = $GLOBALS['DEFAULT_TEMPLATE_NAME'];
             $tpl_path = self::getTplPath($this->_type, $template_name, $templateSwitch);
             if (!$this->_smarty->templateExists($tpl_path)) {
                 //首页兼容,如果找不到首页,就用baidu type下的baidu模板下的首页
                 $this->_type = $GLOBALS['DEFAULT_TEMPLATE_TYPE'];
                 $page_path = self::getTplFolderPath(VUI_TEMPLATE_PATH, $this->_platform, $this->_language, $this->_type);
                 $this->set_template_dir(realpath($page_path));
                 $tpl_path = self::getTplPath($this->_type, $template_name, $templateSwitch);
             }
             if ($this->_smarty->templateExists($tpl_path)) {
                 $tpl_not_found = false;
             }
         }
         if ($tpl_not_found == true) {
             $td_path = $this->_page_dir . ":" . $this->_widget_dir . ":";
             CSmarty::addError("template not found :{$td_path}/{$tpl_path}");
             return false;
         }
     }
     /**
      * set exception/error handler
      */
     $objTplLog = TplLog::getInstance();
     //set_exception_handler("template_exception_handler");
     //set_error_handler("template_error_handler", error_reporting());
     $this->_smarty->clearAllAssign();
     $this->_smarty->assign('_TEMPLATE_TYPE', $this->_type);
     $tplData_tpl_path = $this->_platform . '/' . $this->_language . '/' . $this->_type . '/' . $tpl_path;
     if ($this->_type == VUI_TEMPLATE_ALADDIN_TEMPLATE_TYPE || $this->_type == $GLOBALS['STRUCT_TEMPLATE_TYPE'] || $this->_type == $GLOBALS['ECOM_TEMPLATE_TYPE']) {
         self::$_hi_word = $data['strategy']['hilightWord'];
         foreach ($data['resultData'] as $k => $v) {
             $this->_smarty->assign($k, $v);
         }
     } else {
         $this->_smarty->assign('tplData', $data);
         $objTplLog->addNewTplData($tpl_path, $this->getThisSmarty($this), $data);
     }
     try {
         $result = $this->_smarty->fetch($tpl_path);
     } catch (Exception $e) {
         CSmarty::addError("fail to render template :{$e->getMessage()}");
         return false;
     }
     $this->_smarty->clearAllAssign();
     return $result;
 }