views:

681

answers:

3

I'd like to set a variable in my Symfony action that holds the rendered template data for that action. I'm returning some JSON content with the action, and I'd like to store what the action would be outputting into the JSON and return it.

public function executeAjaxPriceAdditionCreate(sfWebRequest $request)
{
 $this->form = new ProductPriceAdditionAjaxForm();

 $json['success'] = $this->processAjaxPriceAdditionForm($request, $this->form);
 $this->setTemplate('ajaxPriceAdditionNew');
 $json['content'] = ???; // THIS IS WHERE THE RENDERED TEMPLATE CONTENT SHOULD GO.

            $this->getResponse()->setHttpHeader('Content-Type','application/json; charset=utf-8');
 return $this->renderText(json_encode($json));
}
A: 

What I ended up doing was using a flash instead of trying to send JSON. The template of the AJAX content tried to detect the flash at the top, and if so, it did the "success" methods (closing the modal pop-up box).

James Skidmore
+2  A: 

If you name your template as a partial, you can use

$json['content] = $this->getPartial('ajaxPriceAdditionNew');

See getPartial API

Colin Fine
This is another possible method, as long as it works to have your template as a partial. Thanks Colin.
James Skidmore
A: 

exit($this->getPartial('ajaxPriceAdditionNew'));

// apps/frontend/modules/community/templates/_ajaxPriceAdditionNew.php

myclicker