Joomla! Discussion Forums



It is currently Tue Nov 24, 2009 10:05 am (All times are UTC )

 




Post new topic Reply to topic  [ 12 posts ] 
Author Message
Posted: Thu Feb 08, 2007 11:45 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Tue Nov 29, 2005 9:45 pm
Posts: 34
Location: Laredo, TX, USA
Hi,

I am using the following function $mainframe->addCustomHeadTag, but it does not work.

This is the code:
Code:

// css files
$cssfile = $mosConfig_live_site . "/administrator/components/com_cmz/admin.css/admin.cmz.css";
$html = "<link href=\"$cssfile\" rel=\"stylesheet\" type=\"text/css\" />";
$mainframe->addCustomHeadTag( $html );



As far as I am concern, it should give me a link tag to the CSS file I want. But it does not.

I am trying to stick to the API but if it does not work I cannot stick to it. I searched in the forums for the longest time and followed every example and advice I could found about the subject and no good results.

When I do a:
Code:
print_r($mainframe);
die();

To debug, I get the [custom] array with the html that I set, but no actual link tag on the head when the thing runs as is. Is there something wrong with the function $mainframe->addCustomHeadTag();?
??? :(

_________________
Aaron Calderon
Web Designer/Developer


Top
  E-mail  
 
Posted: Fri Feb 09, 2007 12:41 am 
User avatar
Joomla! Virtuoso
Joomla! Virtuoso
Offline

Joined: Fri Sep 16, 2005 8:41 pm
Posts: 3652
Location: NRW - Germany
use
$doc =& JFactory::getDocument();
$doc->addStyleSheet($url);

EDIT: Sorry, forget this, I thought you were talking about Joomla 1.5...

_________________
god doesn't play dice with the universe. not after that drunken night with the devil where he lost classical mechanics in a game of craps.

Since the creation of the Internet, the Earth's rotation has been fueled, primarily, by the collective spinning of English teachers in their graves.


Last edited by Hackwar on Fri Feb 09, 2007 12:43 am, edited 1 time in total.

Top
   
 
Posted: Fri Feb 09, 2007 4:08 am 
User avatar
Joomla! Guru
Joomla! Guru
Offline

Joined: Fri Aug 19, 2005 12:37 am
Posts: 945
Location: Washington, DC / NoVA
Did you call
Code:
global $mainframe
in your code before calling the addCustomHeadTag() function or did you pass $mainframe into a function?

_________________
Joseph L. LeBlanc: http://www.jlleblanc.com
Frontend components start here: /components/com_[name]/[name].php
Backend components start here: /administrator/components/com_[name]/admin.[name].php


Top
   
 
Posted: Fri Feb 09, 2007 9:18 am 
User avatar
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Tue Nov 29, 2005 9:45 pm
Posts: 34
Location: Laredo, TX, USA
Hi,

I have tried that too, but no success.  :( The code is in the main file for a component. I am using the $mainframe a couple of lines before and it woks fine, it is just this function that I cannot get to work. Weird.

_________________
Aaron Calderon
Web Designer/Developer


Top
  E-mail  
 
Posted: Sat Feb 10, 2007 2:05 am 
User avatar
Joomla! Guru
Joomla! Guru
Offline

Joined: Fri Aug 19, 2005 12:37 am
Posts: 945
Location: Washington, DC / NoVA
Very strange. I see this code being used by core components, I assume successfully. Are you able to add tags other than using that function?

_________________
Joseph L. LeBlanc: http://www.jlleblanc.com
Frontend components start here: /components/com_[name]/[name].php
Backend components start here: /administrator/components/com_[name]/admin.[name].php


Top
   
 
Posted: Mon Feb 12, 2007 3:48 am 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Fri Oct 20, 2006 12:10 am
Posts: 27
Hello,
I got a similar but possibly different problem.

I'm using
$mainframe->addCustomHeadTag($head);
in the SmoothGallery Mambot.

The problem is that when I use it on frontpage, it only works exactly once.

If I clear the cache it works again exactly once and then it doesn't work again.

Then I clean cache and it works exactly once and then it doesn't work again.

You get the gist.

I have no idea.

Any Idea?

Any help is appreciated.

Thank you,
Taras


Top
   
 
Posted: Mon Feb 12, 2007 4:18 am 
User avatar
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Tue Nov 29, 2005 9:45 pm
Posts: 34
Location: Laredo, TX, USA
Well,

I do not understand what is going on here. I just gave up. I am using an echo to trow the html and that is it.

_________________
Aaron Calderon
Web Designer/Developer


Top
  E-mail  
 
Posted: Mon Feb 12, 2007 4:23 am 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Fri Oct 20, 2006 12:10 am
Posts: 27
yeah but that sucks,
in my case that would make it not XHTML valid.
Which I don't want to do.
I don't understand what it is, it doesn't make any sense.
Ahhgh


Top
   
 
Posted: Sat May 05, 2007 9:32 am 
Joomla! Fledgling
Joomla! Fledgling
Offline

Joined: Fri May 04, 2007 7:57 am
Posts: 3
Hi to all !

The $mainframe->addCustomHeadTag function works fine.

It just adds its html argument to an array property of the $mainframe object (which acts as a buffer).

It works so well that you can even use it within modules, your html will be added to the $mainframe property... but will never be included within the section of your template ! In fact, once the mosShowHead() function is fired in the section of your template, using the $mainframe->addCustomHeadTag function afterward (in a module, for instance) is simply useless.

I've founded a solution to this problem which consists in restructuring the code inside the index.php file of any standard joomla templates so that the mosShowHead() function is fired AFTER the LAST call of the $mainframe->addCustomHeadTag function.

Let's start with a standard joomla template index.php file :

Code:
<!-- JOOMLA HEADERS -->
<head>
<?php mosShowHead(); ?>
<!-- OTHER STUFF -->
</head>

<body>

<!-- BODY PART -->

</body>
</html>


This file should be restructured as follows :

Code:
<!-- JOOMLA HEADERS -->

<?php
//Start output buffering 
ob_start(); 
?> 

<!-- BODY PART -->

<?php 
//Store the contents of the buffer in the $body variable
$body = ob_get_contents();
//Stop output buffering 
ob_end_clean();
?>

<head>
<?php mosShowHead(); ?>
<!-- OTHER STUFF -->
</head>

<body>

<?php echo $body; ?>

</body>
</html>


Using this approach will help you to easily create effective XHTML-valid modules.

PS : Sorry for the last reply  ;)

-BoR


Last edited by bestofrisk on Sat May 05, 2007 12:15 pm, edited 1 time in total.

Top
  E-mail  
 
Posted: Tue May 08, 2007 2:48 am 
User avatar
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Tue Nov 29, 2005 9:45 pm
Posts: 34
Location: Laredo, TX, USA
Hi bestofrisk,

Thanks for your clarification. I just found out the same as you did. Although my issue was related with the backend, where the function "mosShowHeas()" is not implemented, so even-though the the function addCustomHeadTag() works as you explained, the tags are not placed within the head on the template.

It is said to be fixed on Joomla! 1.5, though.

_________________
Aaron Calderon
Web Designer/Developer


Top
  E-mail  
 
Posted: Thu May 24, 2007 1:08 pm 
User avatar
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Sun Apr 02, 2006 6:36 pm
Posts: 252
Location: Watansoppeng
You can add a function in your component class,
Code:
<?php
define('_BASEURL',$mosConfig_live_site.'/components/yourcomponent');

function loadStyle($filename){
    global $mainframe;
    $html = "<link href=\""._BASEURL."/your_css_folder/$filename.css\" type=\"text/css\" rel=\"stylesheet\" />\n";
    return $mainframe->addCustomHeadTag($html);
}
?>


then call this function in yourcomponent.php

Code:
<?php loadStyle('sample'); ?>


It works for me...

_________________
Hati-hati bro!!! Gara-gara gw terlalu menyukai Joomla makanya ampe sekarang gw masih "menJombLo" :)
~ Joomlaku: http://guffy.5gigs.com
~ Current work: http://soppengkab.go.id


Top
   
 
Posted: Thu May 31, 2007 11:00 am 
Joomla! Enthusiast
Joomla! Enthusiast
Offline

Joined: Thu Jul 20, 2006 7:15 am
Posts: 148
Location: UK
an even easier way would be to create a position just for the header, and include the module in your template just before the header:

Code:
<?php

mosLoadModules ( 'header_mod' );

mosShowHead();

?>


The module can be set to display in all pages, just make sure to ouput only the tag required.
:pop

_________________
Web Developer

www.obbec.com


Top
  E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

Quick reply

 



Who is online

Users browsing this forum: No registered users and 21 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group