From Joomla! Documentation

This page is tagged because itNEEDS REVIEW. You can help the Joomla! Documentation Wiki by contributing to it.More pages that need help similar to this one are here.NOTE-If you feel the need is satistified, please remove this notice.

Contents

NOTE: This documentation was not previously updated for Joomla! 3.2. I have made some updates to bring it closer to what is needed for Joomla! 3 but admittedly, I still don't have this functionality working. Additional corrections and contributions would be greatly appreciated! Erik Jorgensen 12/10/2013.

Using JToolBar

It's now simpler to use JToolBar in the front end than it was in Joomla! 1.5 as it only requires two steps.

Step 1

Using the MVC architecture, add a function definition to view.html.php file in the view you wish to add the toolbar to.

function getToolbar(){// add required stylesheets from admin template$document= JFactory::getDocument();$document->addStyleSheet('administrator/templates/isis/css/template.css');//now we add the necessary stylesheets from the administrator template//in this case i make reference to the isis default administrator template in joomla 3.2$document->addCustomTag('<link href="administrator/templates/isis/css/template.css" rel="stylesheet" type="text/css" />'."\n\n");//load the JToolBar library and create a toolbar
jimport('cms.html.toolbar');$bar=&new JToolBar('toolbar');//and make whatever calls you require$bar->appendButton('Standard','save','Save','yourcom.save',false);$bar->appendButton('Separator');$bar->appendButton('Standard','cancel','Cancel','yourcom.cancel',false);//generate the html and returnreturn$bar->render();}

Step 2

Now in the corresponding tmpl file, you simply need to add code like the following (added here to a default.php file in the tmpl folder of the view to which the code above was added to the view.html.php file. Note I say "like" the following, changes may be required. I'm including the <form> declaration html (the toolbar MUST be in a form with the id of "adminForm" in order for it to work.

You'll note the [div class="clr"] which you may or may not need depending on your own design requirements. If you don't add the div tag, slapping this code into an existing component front end will place the buttons to the right and level with the content on the left. Also, and as explained above, you'll need to add functions within the controller that is called when one of the toolbar buttons is pressed, to process the request gracefully.

Using JToolBar with Search Engine Friendly enabled (SEF)

When using the toolbar on the frontend,the standard buttons will sometimes bug out. This is usually because Search Engine Friendly urls is defined.

What happens is that instead of going to index.php?option=com_yourcom&view=&...#, it will go to index.php/friendlyurl# . This bugs out many users.

Using these two together can be done,however. There's two tricks to it. First, create a buttons folder under your main component folder and create a frontend.php file with a class called JToolbarButtonFrontend which extends JToolbarButton. Include a jimport('cms.html.toolbar') statement to include the standard button classes.

This file will need the following code to create the search engine friendly front end buttons.

Be sure to add the new "buttons" directory to your package xml file! (yourcom.xml)

You can now use the 'Frontend' buttons in the getToolbar methods in your view.html.php files:

//load the JToolBar library and create a toolbar
jimport('cms.html.toolbar');$this->bar=new JToolBar('toolbar');//and make whatever calls you require$this->bar->appendButton('Frontend','save','Save','yourcom.save',false);$this->bar->appendButton('Separator');$this->bar->appendButton('Frontend','cancel','Cancel','yourcom.cancel',false);//generate the html and returnreturn$this->bar->render();