Search code examples
joomlacomponentsjtoolbar

Add image to Joomla JToolBar custom link button


Hi I have created a custom button link in the admin section of my component, something like this:

$bar = & JToolBar::getInstance('toolbar');
$bar->appendButton( 'Link', 'export', 'Export', 'index.php?option=com_component&task=export&format=raw' );

However no image is assigned to it and I don't know how to assign one to the button. Does anyone know how I can do this?


Solution

  • You need to create CSS class called icon-32-export with image background.

    Here is an example:

    <?php
    
    // Add CSS class to the document, it's better to have it in external CSS document
    $imgPath = JRoute::_('/administrator/templates/khepri/images/toolbar/icon-32-new.png');
    JFactory::getDocument()->addStyleDeclaration(".icon-32-export { background: url($imgPath); }");
    
    //
    $bar = & JToolBar::getInstance('toolbar');
    $url = JRoute::_('index.php?option=com_component&task=export&format=raw');
    $bar->appendButton( 'Link', 'export', 'Export', $url);
    
    ?>