I'm making an AJAX call to my JController and would like to send back a 'partial' view for display within the existing page, populated with some data.
Is it possible to load a file from <view>/tmpl/
, inject data into it and store the resulting snippet?
I'm thinking I need to do something like:
controller.php (in action method)
$view = $this->getView('MyView', 'results'); // loads view.results.php
$view->assignRef('data', $response); // assign data
$storedView = $view->display(); // store the view
view.results.php
function display($tpl = null){
return $this->loadTemplate('results'); // loads '/<view>/tmpl/default_results.php'
}
EDIT
I've edited the earlier incorrect code above to what seems to be working.
Is this best practice for this particular use case? Would it be considered bad form to simply add a new method to the existing view.html.php
that returns the loaded template?
assignRef()
andassign()
are deprecated. So$view->assignRef('data', $response);
should be$view->data = $response;
.