I've got some custom buttons in my Joomla component and I want them to open in a modal window like with the batch button in the com_content component. Anyone has got any idea on how to do it?

Thank you!

1 Answer 1


It's actually pretty simple.

In view.html.php, load modal library, if it's not already done:


For adding button to toolbar, use:

// Toolbar object
$toolbar = JToolBar::getInstance('toolbar');
$layout = new JLayoutFile('joomla.toolbar.popup');

// Render the popup button
$dhtml = $layout->render(array('name' => 'test', 'text' => JText::_('Custom button'), 'class' => 'icon-archive', 'doTask' => ''));
$toolbar->appendButton('Custom', $dhtml);

name must match modal id after -. You can change class for different icons.

In default.php or in any file in tmpl folder add modal div, what will be shown after clicking on link

<div class="modal hide fade" id="modal-test">
  <div class="modal-header">
    <button type="button" role="presentation" class="close" data-dismiss="modal">x</button>
    <h3>Modal title</h3>
  <div class="modal-body">
    Modal content here
  <div class="modal-footer">
    <button class="btn" type="button" data-dismiss="modal">
      <?php echo JText::_('JCANCEL'); ?>
  • would this also work if the button is inside of the toolbar? Because right now I create my custom toolbar button with JToolbarHelper::custom inside of view.html.php. I'm sorry I wasn't clear in my post
    – republicca
    Commented Aug 4, 2015 at 9:28
  • @republicca I edited my answer for adding button to toolbar.
    – Rene Korss
    Commented Aug 4, 2015 at 10:26
  • 1
    Yes. You just have to load new JForm in your view.html.php and then print it in modal. I can see you have posted new question for this. But I would create new view what and then load that into modal with AJAX. See example JSFiddle here.
    – Rene Korss
    Commented Aug 12, 2015 at 8:49
  • 1
    Answered in your new question.
    – Rene Korss
    Commented Aug 19, 2015 at 8:55
  • 1
    Thanks @ZacharyDraper, added doTask to avoid notice.
    – Rene Korss
    Commented Aug 29, 2018 at 6:57

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.