public function preRender() { if ($this->handle) { $context = Template::getContext(); if (Template::getView() == 'Misc/Error') { /** @var Error $error */ $error = $context['instance']; $this->outputJson(array('code' => $error->getCode() ? $error->getCode() : 500, 'data' => null, 'hasError' => true, 'message' => $error->getMessage())); } elseif (Template::getView() == 'Misc/Redirect') { $this->outputJson(array('code' => 302, 'data' => null, 'hasError' => true, 'message' => $context['text'] ? $context['text'] : 'JSON request has been redirected', 'target' => $context['link'])); } else { $this->outputJson(array('code' => self::$statusCode, 'data' => $context)); } } }