Example #1
0
 public function render($data = array())
 {
     if (isset($data['_idle'])) {
         $this->context->isIdle(true);
         unset($data['_idle']);
     }
     if (count($data) > 0) {
         $this->context->push($data);
     }
     ob_start();
     if (!is_null($this->forced_method)) {
         $method = $this->forced_method;
     } else {
         $method = self::getActionMethod($this->action, $this->context);
         if (!$method) {
             throw new \Exception('No template: ' . get_class($this) . '.' . $this->action);
         }
     }
     if ($this->level > 50) {
         fx::log('recursion in', get_class($this), $method);
         return '<div class="fx_template_error">bad recursion?</div>';
     }
     $profiler = $this->getProfiler();
     if ($profiler) {
         $sign = preg_replace("~^fx_template_~", '', get_class($this)) . '::' . preg_replace("~^tpl_~", '', $method);
         $profiler->block('<b style="color:#009;">tpl:</b> ' . $sign);
     }
     try {
         $this->{$method}($this->context);
     } catch (\Exception $e) {
         if (preg_match("~Less_Exception~", get_class($e))) {
             fx::log('Less compiler exception', get_class($this) . ':' . $method, $e->getMessage(), $e->currentFile);
         } else {
             fx::log('template exception', $e->getMessage());
         }
     }
     $result = ob_get_clean();
     if (fx::isAdmin()) {
         if ($this->context->isIdle()) {
             if ($profiler) {
                 $profiler->stop();
             }
             return $result;
         }
         if (!$this->parent) {
             self::$count_replaces++;
             $result = Template::replaceAreas($result);
             $result = Field::replaceFields($result);
         }
     }
     if ($profiler) {
         $profiler->stop();
     }
     return $result;
 }