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


function display($tpl = null){
    return $this->loadTemplate('results'); // loads '/<view>/tmpl/default_results.php'


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?

  • 2
    Notice that assignRef() and assign() are deprecated. So $view->assignRef('data', $response); should be $view->data = $response;.
    – Farahmand
    Jul 30, 2014 at 21:32
  • @codinghands If you have found a solution that seems to be working, submit it is an answer instead of as part of the original question. You can answer your own questions! What you has looks to be a valid answer, for sure! Sep 11, 2014 at 2:35

1 Answer 1


Your URL for the partial view / task needs to look like this:


You can also create a new method in the controller, if needed. Make sure that the default display() method is not overridden in a way that hinders the setting of a different view.

Now create the following files:


defined('_JEXEC') or die;

class ExampleViewPartial extends JViewLegacy
    function display($tpl = null)
        // Get the data needed for the view ...

        // Call parent



echo 'Hello partial world!';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.