• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1251
  • Last Modified:

Joomla: adding css using addCustomHeadTag in specific order.

Hello,

I added a css in my component using $mainframe->addCustomHeadTag

but when I accessed the component the css I added was loaded first and some of its styles are overridden by the css loading after.

Question: how can I specify that my css will load last.?

thank you..
0
Rev22only
Asked:
Rev22only
  • 7
  • 4
1 Solution
 
Jesse MatlockUX EngineerCommented:
One concern is that this tag is depracated as of 1.5 (http://api.joomla.org/Joomla-Framework/Application/JApplication.html#addCustomHeadTag) so you will want to use JDocumentHTML::addCustomTag() instead.. here is some information on it.
http://api.joomla.org/Joomla-Framework/Document/JDocumentHTML.html#methodaddCustomTag
and
http://api.joomla.org/__filesource/fsource_Joomla-Framework_Document_joomladocumenthtmlhtml.php.html#a157
Hope that helps.. once you review this.. let me know what questions you have ok.
0
 
Jesse MatlockUX EngineerCommented:
Here is some additional info from the API Wiki:
http://docs.joomla.org/JDocumentHTML/addCustomTag

0
 
Jesse MatlockUX EngineerCommented:
And finally, you may want to consider using the addHeadLink declaration:
http://docs.joomla.org/JDocumentHTML/addHeadLink#Examples

or the addStyleSheet declaration:
http://docs.joomla.org/JDocument/addStyleSheet#Example_1
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Rev22onlyAuthor Commented:
Hello

thanks for the input I have now used the code:
$doc =& JFactory::getDocument();
$doc->addStyleSheet( 'http://www.example.com/css/mystylesheet.css' );

still I question is how can I change the order.. this css is being added first

thanks
0
 
Jesse MatlockUX EngineerCommented:
One option might be calling the addStyleSheet code after the the rest have loaded, I haven't tried this, but something along these lines:

$mainframe->registerEvent('onAfterDispatch', 'addMyStyleSheet');

function addMyStyleSheet()
{
    $document  = & JFactory::getDocument();
    $document->addStyleSheet( JURI::base() . 'directory/directory/mystylesheet.css',
                                          'text/css', null, array() );
}

Here's the API execution order that may help you in deciding which code to execute it with.. depending upon when you need it to load:
http://docs.joomla.org/API_Execution_Order

Hopefully this will help :)

And Happy New Year !
0
 
Rev22onlyAuthor Commented:
isn't there any joomla way to do it..
0
 
Jesse MatlockUX EngineerCommented:
not that I am aware of.. it would be done programatically as in the example above, or within the page elements being loaded, but there is not 'option' for ordering within Joomla outside of executing the code 'on event'..
0
 
Rev22onlyAuthor Commented:
anyone else has some inputs on this...
thanks for your reply cloud9manager.
0
 
Jesse MatlockUX EngineerCommented:
Anytime, I will continue to research this for you as well..  :)
0
 
Jesse MatlockUX EngineerCommented:
From what I have researched, this is the preferred method to add a stylesheet to the head tag of Joomla.. and there currently is no other option to order them in a specific order, unless you call your particular head tag addition, after an event.
0
 
Rev22onlyAuthor Commented:
yet another question I want to close because there is no solution.
In this case there seems to be no straight forward solution in Joomla itself. I will try to raise the question with the Joomla developers. If there is any solution I will post it here.
For now I need to close this question by accepting this as possible solution and so that I can ask new questions.
Thanks for all your replies.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now