2013-07-02 96 views
1

我正在开发一个组件为Joomla 3.1,我在向JToolbarHelper :: custom()按钮添加图像时有些困难....在此基础上tutorial,我使用下面的代码:Joomla 3.1 - JToolbarHelper:自定义按钮的图像不显示/显示

JToolBarHelper::custom('', '../administrator/components/com_hmi/assets/css/icon-32-window.png', 
        '../administrator/components/com_hmi/assets/css/icon-32-window.png', 'Window', true); 

然而按钮和其文本显示而不是按钮图标/图像....谁能帮弄清楚什么是错。我尝试了一些其他解决方案,但得到了相同的结果:/

回答

7

使用className并注入css。即从我的分量小助手(见 “基督教儿童基金” 类)

函数定义:

custom($task = '', $icon = '', $iconOver = '',... 

我的代码:

JToolBarHelper::custom('trash_n_cache.cleanfscache','ccfs' ,'ccfs',... 

渲染上的Joomla 2.5这个标记:

<a class="toolbar" onclick="Joomla.submitbutton('trash_n_cache.cleanfscache')" href="#"> 
    <span class="icon-32-ccfs"></span> 
    Clean cache 
</a> 

和Joomla 3.x上的标记:

<button class="btn btn-small" onclick="Joomla.submitbutton('trash_n_cache.cleanfscache')" href="#"> 
<i class="icon-ccfs "></i> 
Clean cache 
</button> 

我的风格是:(请注意,J2.5图标为32 * 32,在的Joomla 3.x的是16 * 16)

.icon-16-ccfs, i.icon-ccfs { 
    background-image: 
     url(../images/cachefs16.png) 
} 

.icon-32-ccfs { 
    background-image: 
     url(../images/cachefs32.png) 
} 

,你可以注入:

$document = JFactory::getDocument(); 
$document->addStyleDeclaration($cssRules) 

中或在外部的CSS链路作为资源:

$document = JFactory::getDocument(); 
$document->addStyleSheet("components/com_littlehelper/assets/css/littlehelper.css");  
+0

感谢队友!! :)设法解决问题后两天试图找出它....你的答案确实给了更多的见解:) – drew