I'm trying to add a custom JToolbar button to my list view that will export the list contents to excel. I created a new task in my list controller to render the raw view class in a file called view.raw.php. However I can't get the content to load the raw data only.

I copied the relevant controller code from com_banners tracks.raw.php controller

Controller method:

public function exportToExcel()
    // Get the document object.
    $document   = JFactory::getDocument();
    $vName      = 'Mylist';
    $vFormat    = 'raw';

    // Get and render the view.
    if ($view = $this->getView($vName, $vFormat))
        // Get the model for the view.
        $model = $this->getModel($vName);

        // Push the model into the view (as default).
        $view->setModel($model, true);

        // Push document object into the view.
        $view->document = $document;


And a simple test display method in my view.raw.php file:

public function display($tpl = null)
   echo "Test";

This displays "Test" but loads the template too.

I've tried using $document->setType('Raw') but this is giving me an

Unable to load renderer class


The reason for this is that it is looking for


which does not exist.

Maybe I'm going about this in the wrong way but how should I do this correctly?

1 Answer 1


You need to specify the document type in the URL call with format=raw. Joomla will then automatically load the view.raw.php file. You don't even need a special controller for that.

To create the toolbar button you can use this:

    $bar = JToolBar::getInstance('toolbar');
    $bar->appendButton('Custom', '<button onclick="window.location.href = \'http://www.google.com\';">Export</button>', 'export');
  • But how to pass the URL to the toolbar button? AFAIK it is not possible, you can only specify controller's name and task. Apr 30, 2014 at 6:38
  • Using JToolbarHelper it's not possible, but it should be possible using JToolbar->appendButton() like we don for the batch button. I'll check :)
    – Bakual
    Apr 30, 2014 at 6:46

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.