Custom image for JToolbarHelper::title
-
- Joomla! Enthusiast
- Posts: 126
- Joined: Fri Jul 11, 2008 9:08 pm
Custom image for JToolbarHelper::title
I try to use JToolbarHelper::title to display a title and a custom png image file.
The title works - duhuh - but the image file does not show up.
Where do those images need to reside? Can I configure this? Do I need to include something or register something somewhere beforehand? Are there size constraints?
Are these questions already answered somewhere? I could not find them.
The title works - duhuh - but the image file does not show up.
Where do those images need to reside? Can I configure this? Do I need to include something or register something somewhere beforehand? Are there size constraints?
Are these questions already answered somewhere? I could not find them.
- jwwicks
- Joomla! Enthusiast
- Posts: 102
- Joined: Fri Jul 04, 2008 4:49 am
- Location: Sacramento, Ca
Re: Custom image for JToolbarHelper::title
Hello Parvus,
looks for the generic.png file in the administrator/images directory. If you want yours to be displayed then you'll probably want to create a images directory for your component/module etc... and then change the call to
Might be a shorter path statement available but couldn't find anything under JApplicationHelper::getPath. Although assuming that you have this call in a file called admin.mycomponent.html.php,
Should work out as well, assuming of course a com_mycomponent/images directory and a mytoolbar_title.png file in that directory...
JW
PS. I stand corrected. The code strips everthing from the icon parameter and as mentioned below you need to add a line to the icons.css file of your template such as...
And your admin.mycomponent.html.php call should be..
Thanks sectuer
A call such andParvus wrote:I try to use JToolbarHelper::title to display a title and a custom png image file.
The title works - duhuh - but the image file does not show up.
Where do those images need to reside? Can I configure this? Do I need to include something or register something somewhere beforehand? Are there size constraints?
Are these questions already answered somewhere? I could not find them.
Code: Select all
JToolbarHelper::title(JText::_('Some Title'), 'generic.png');
Code: Select all
JToolbarHelper::title(JText::_('Some Title'), JPATH_COMPONENT.DS.'com_mycomponent'.DS.'images'.DS.'mytoolbar_title.png');
Code: Select all
class TOOLBAR_foo
{
function _DEFAULT(){
JToolBarHelper::title(JText::_("My Component"), dirname(__FILE__).DS.'images'.DS.'mytoolbar_title.png');
}
}
JW
PS. I stand corrected. The code strips everthing from the icon parameter and as mentioned below you need to add a line to the icons.css file of your template such as...
Code: Select all
.icon-48-mytoobar_title { background-image: url(../images/header/icon-48-mytoolbar_title.png); }
Code: Select all
class TOOLBAR_foo
{
function _DEFAULT(){
JToolBarHelper::title(JText::_("My Component"), 'mytoolbar_title');
}
}
Last edited by jwwicks on Sat Jul 12, 2008 5:52 am, edited 4 times in total.
Computers are useless, they can only give you answers. - Pablo Picasso
-
- Joomla! Enthusiast
- Posts: 146
- Joined: Tue Nov 08, 2005 9:32 am
- Location: Malaysia
Re: Custom image for JToolbarHelper::title
Hi,
In any case, what happens is that the string you pass in the JToolbarHelper::title function is appended to 'icon-48-' to create the name of a class. So, let's say you want a special icon there, this is your code:
Then in your template css file you add a class: .icon-48-anythingyouwant and that's where you give the path to your image.
If you're using Khepri, the file where you find these classes is /templates/khepri/css/icons.css
Hope this helps
will not work because the 'generic.png' is actually not handled as an image but as a class instead. It is actually striped of the .png by the title function and used as "generic" only (see below) (my guess is that the default 'generic.png' just is the remain of some older version)JToolbarHelper::title(JText::_('Some Title'), JPATH_COMPONENT.DS.'com_mycomponent'.DS.'images'.DS.'mytoolbar_title.png');
In any case, what happens is that the string you pass in the JToolbarHelper::title function is appended to 'icon-48-' to create the name of a class. So, let's say you want a special icon there, this is your code:
Code: Select all
JToolbarHelper::title(JText::_('Some Title'), 'anythingyouwant' );
If you're using Khepri, the file where you find these classes is /templates/khepri/css/icons.css
Hope this helps
-
- Joomla! Enthusiast
- Posts: 126
- Joined: Fri Jul 11, 2008 9:08 pm
Re: Custom image for JToolbarHelper::title
Thanks a lot!
I created a separate css file, which I added in admin.mycomponent.php with Using the css code listed above, I got it working: I just needed to give the path relative to the com_mycomponent directory.
The way the png files are handled is pretty obscure, don't you think? I'm glad it works now! Tx!
I created a separate css file, which I added in admin.mycomponent.php with
Code: Select all
$document = &JFactory::getDocument();
$css = $mainframe->getSiteURL().'administrator'.DS.'components'.DS.'com_mycomponent'.DS.'mycomponent.css';
$document->addStyleSheet( $css, 'text/css', null, array() );
The way the png files are handled is pretty obscure, don't you think? I'm glad it works now! Tx!
-
- Joomla! Enthusiast
- Posts: 146
- Joined: Tue Nov 08, 2005 9:32 am
- Location: Malaysia
Re: Custom image for JToolbarHelper::title
Hi Parvus,
glad it worked out I have to agree with you that the default of the method stated as 'generic.png' is a bit disturbing.
Actually handling this as a class is very good because you can do so much more if you wish to (adding border, margins, and more!). It's just that default value that is misleading.
I'm quite convinced that it's only something that is left from the way the title image used to be handled. But the core developers are already doing SO much that I think we can't blame them for small small mistakes. This should probably be posted on one of the development forums as a requested correction to... what do you think ... the documentation?
Just a detail on your code:
I believe you should not use the DS constant when calling the path to a style sheet. I'm assuming you are running a Linux server if your code worked, whereby DS will be a "/" . CSS sheet are handled by HTML and therefore it's only "/", no matter what server you are on, no DS.
Also can replace although I'm not sure which one is considered more correct.
Again, glad things worked out.
Mat
glad it worked out I have to agree with you that the default of the method stated as 'generic.png' is a bit disturbing.
Actually handling this as a class is very good because you can do so much more if you wish to (adding border, margins, and more!). It's just that default value that is misleading.
I'm quite convinced that it's only something that is left from the way the title image used to be handled. But the core developers are already doing SO much that I think we can't blame them for small small mistakes. This should probably be posted on one of the development forums as a requested correction to... what do you think ... the documentation?
Just a detail on your code:
I believe you should not use the DS constant when calling the path to a style sheet. I'm assuming you are running a Linux server if your code worked, whereby DS will be a "/" . CSS sheet are handled by HTML and therefore it's only "/", no matter what server you are on, no DS.
Also
Code: Select all
JURI::base()
Code: Select all
$mainframe->getSiteURL().'administrator'
Again, glad things worked out.
Mat
-
- Joomla! Enthusiast
- Posts: 126
- Joined: Fri Jul 11, 2008 9:08 pm
Re: Custom image for JToolbarHelper::title
Thank you for your details, they are greatly appreciated.
- juanparati
- Joomla! Enthusiast
- Posts: 123
- Joined: Thu Nov 08, 2007 6:00 pm
- Location: Aarhus (Denmark)
Re: Custom image for JToolbarHelper::title
Don't try change the icon path because jwwicks is right, you must change the CSS.
I have inspect administrator/includes/toolbar.php and . . .
I have inspect administrator/includes/toolbar.php and . . .
Code: Select all
/**
* Title cell
* For the title and toolbar to be rendered correctly,
* this title fucntion must be called before the starttable function and the toolbars icons
* this is due to the nature of how the css has been used to postion the title in respect to the toolbar
* @param string The title
* @param string The name of the image
* @since 1.5
*/
function title($title, $icon = 'generic.png')
{
global $mainframe;
//strip the extension
$icon = preg_replace('#\.[^.]*$#', '', $icon);
$html = "<div class=\"header icon-48-$icon\">\n";
$html .= "$title\n";
$html .= "</div>\n";
$mainframe->set('JComponentTitle', $html);
}
From the code to the reality!
- juanparati
- Joomla! Enthusiast
- Posts: 123
- Joined: Thu Nov 08, 2007 6:00 pm
- Location: Aarhus (Denmark)
Re: Custom image for JToolbarHelper::title
For more info see:
http://dev.joomla.org/component/option, ... itleimage/
http://dev.joomla.org/component/option, ... itleimage/
From the code to the reality!
- jwwicks
- Joomla! Enthusiast
- Posts: 102
- Joined: Fri Jul 04, 2008 4:49 am
- Location: Sacramento, Ca
Re: Custom image for JToolbarHelper::title
Hello Mat,
The line in the css file is..
The HTML produced is..
and
The toolbar.wrmswebawards.html.php looks like..
Verified the files are in place but no icon. Am I missing something...
Figured it out. Seems the CSS file can't have anything after the url, when I deleted the no-repeat left from the background-image: directive, all is well.
Thanks,
JW
I've been trying to get the code to work as well. I've added the line in the admin.mycomponent.phpsecteur wrote:Hi Parvus,
glad it worked out I have to agree with you that the default of the method stated as 'generic.png' is a bit disturbing.
Alsocan replaceCode: Select all
JURI::base()
although I'm not sure which one is considered more correct.Code: Select all
$mainframe->getSiteURL().'administrator'
Mat
Code: Select all
$document =& JFactory::getDocument();
$cssFile = JURI::base(true).'/components/com_wrmswebawards/css/wrmswebawards.css';
$document->addStyleSheet($cssFile, 'text/css', null, array());
Code: Select all
.icon-48-wrms_toolbar_title { background-image: url(../images/wrms_toolbar_title.png) no-repeat left; }
Code: Select all
<link rel="stylesheet" href="/administrator/components/com_wrmswebawards/css/wrmswebawards.css" type="text/css" />
Code: Select all
<div class="header icon-48-wrms_toolbar_title">
WRMS Web Awards
</div>
Code: Select all
function _DEFAULT(){
JToolBarHelper::title(JText::_("WRMS Web Awards"), 'wrms_toolbar_title');
JToolBarHelper::publishList();
JToolBarHelper::unpublishList();
JToolBarHelper::editList();
JToolBarHelper::deleteList();
JToolBarHelper::addNew();
}
Figured it out. Seems the CSS file can't have anything after the url, when I deleted the no-repeat left from the background-image: directive, all is well.
Thanks,
JW
Computers are useless, they can only give you answers. - Pablo Picasso
- mika
- Joomla! Intern
- Posts: 75
- Joined: Tue Aug 23, 2005 9:04 pm
- Location: Kiel - Germany
- Contact:
Re: Custom image for JToolbarHelper::title
Hello,
i will use a image with other dimension (48x112px). When i test it, the title text is written above the image.
It is not possible to use other dimensions as 48x48?
Has anybody a suggestion for me?
i will use a image with other dimension (48x112px). When i test it, the title text is written above the image.
It is not possible to use other dimensions as 48x48?
Has anybody a suggestion for me?
- juanparati
- Joomla! Enthusiast
- Posts: 123
- Joined: Thu Nov 08, 2007 6:00 pm
- Location: Aarhus (Denmark)
Re: Custom image for JToolbarHelper::title
Yes, you can, but must change the CSS definition of icon class.
From the code to the reality!
- nag_sunny
- Joomla! Enthusiast
- Posts: 157
- Joined: Sat Mar 28, 2009 6:29 am
- Contact:
Re: Custom image for JToolbarHelper::title
Hello mika,
Just add few spaces as needed before the title as shown below:
JToolBarHelper::title(" " . JText::_('your title')
Thanks,
Maverick
Just add few spaces as needed before the title as shown below:
JToolBarHelper::title(" " . JText::_('your title')
Thanks,
Maverick
http://www.corejoomla.com
CjForum, CjFit, Community Surveys, Community Quiz, Community Answers, Community Polls, GPS Tools, Community Quotes, Crosswords, CjBlog
CjForum, CjFit, Community Surveys, Community Quiz, Community Answers, Community Polls, GPS Tools, Community Quotes, Crosswords, CjBlog
- tusker
- Joomla! Ace
- Posts: 1075
- Joined: Tue Dec 25, 2007 2:15 pm
- Location: Baroda - India
- Contact:
Re: Custom image for JToolbarHelper::title
yes, i think it can be changed.mika wrote:Hello,
i will use a image with other dimension (48x112px). When i test it, the title text is written above the image.
It is not possible to use other dimensions as 48x48?
Has anybody a suggestion for me?
ONE WORLD OPEN WORLD - WAR TODAY GIVE PEACE A CHANCE
http://indiavoice.info - India News & Information Portal
http://indiadaily.indiavoice.info - India Daily Infotainment
(Powered by Joomla!)
http://indiavoice.info - India News & Information Portal
http://indiadaily.indiavoice.info - India Daily Infotainment
(Powered by Joomla!)