Reputation: 82
I need to load a part of view in phalcon for returning in ajax call. For this i need to set the view in variables. Now what happening is i am getting all templates including header and footer.
Upvotes: 1
Views: 452
Reputation: 3876
You need to disable rest of the view rendering. Example of exact situation (returning JSON response for AJAX)
$viewParams = [
'param1' => '....',
'param2' => '....',
];
$response = new \stdClass();
// Render view into a variable
$this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_NO_RENDER);
$response->html = $this->view->getRender('yourTemplateDir', 'yourTemplateName', $viewParams, function($view) {
$view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
});
// Disable view
$this->view->disable();
return $this->response->setJsonContent($response);
Upvotes: 3