Problems with: $mainframe->addCustomHeadTag();

For Joomla! 1.0 Coding related discussions.
Locked
User avatar
acalderon
Joomla! Apprentice
Joomla! Apprentice
Posts: 34
Joined: Tue Nov 29, 2005 9:45 pm
Location: Laredo, TX, USA
Contact:

Problems with: $mainframe->addCustomHeadTag();

Post by acalderon » Thu Feb 08, 2007 11:45 pm

Hi,

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

This is the code:

Code: Select all


// 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: Select all

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

User avatar
Hackwar
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3763
Joined: Fri Sep 16, 2005 8:41 pm
Location: NRW - Germany
Contact:

Re: Problems with: $mainframe->addCustomHeadTag();

Post by Hackwar » Fri Feb 09, 2007 12:41 am

use
$doc =& JFactory::getDocument();
$doc->addStyleSheet($url);

EDIT: Sorry, forget this, I thought you were talking about Joomla 1.5...
Last edited by Hackwar on Fri Feb 09, 2007 12:43 am, edited 1 time in total.
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.

User avatar
jlleblanc
Joomla! Guru
Joomla! Guru
Posts: 963
Joined: Fri Aug 19, 2005 12:37 am
Location: Washington, DC / NoVA
Contact:

Re: Problems with: $mainframe->addCustomHeadTag();

Post by jlleblanc » Fri Feb 09, 2007 4:08 am

Did you call

Code: Select all

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

User avatar
acalderon
Joomla! Apprentice
Joomla! Apprentice
Posts: 34
Joined: Tue Nov 29, 2005 9:45 pm
Location: Laredo, TX, USA
Contact:

Re: Problems with: $mainframe->addCustomHeadTag();

Post by acalderon » Fri Feb 09, 2007 9:18 am

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

User avatar
jlleblanc
Joomla! Guru
Joomla! Guru
Posts: 963
Joined: Fri Aug 19, 2005 12:37 am
Location: Washington, DC / NoVA
Contact:

Re: Problems with: $mainframe->addCustomHeadTag();

Post by jlleblanc » Sat Feb 10, 2007 2:05 am

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

turokthemighty
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Fri Oct 20, 2006 12:10 am
Contact:

Re: Problems with: $mainframe->addCustomHeadTag();

Post by turokthemighty » Mon Feb 12, 2007 3:48 am

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

User avatar
acalderon
Joomla! Apprentice
Joomla! Apprentice
Posts: 34
Joined: Tue Nov 29, 2005 9:45 pm
Location: Laredo, TX, USA
Contact:

Re: Problems with: $mainframe->addCustomHeadTag();

Post by acalderon » Mon Feb 12, 2007 4:18 am

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

turokthemighty
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Fri Oct 20, 2006 12:10 am
Contact:

Re: Problems with: $mainframe->addCustomHeadTag();

Post by turokthemighty » Mon Feb 12, 2007 4:23 am

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

bestofrisk
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Fri May 04, 2007 7:57 am

Re: Problems with: $mainframe->addCustomHeadTag();

Post by bestofrisk » Sat May 05, 2007 9:32 am

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: Select all

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

<body>

<!-- BODY PART -->

</body>
</html>
This file should be restructured as follows :

Code: Select all

<!-- 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.

User avatar
acalderon
Joomla! Apprentice
Joomla! Apprentice
Posts: 34
Joined: Tue Nov 29, 2005 9:45 pm
Location: Laredo, TX, USA
Contact:

Re: Problems with: $mainframe->addCustomHeadTag();

Post by acalderon » Tue May 08, 2007 2:48 am

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

User avatar
Zach Guffron
Joomla! Explorer
Joomla! Explorer
Posts: 257
Joined: Sun Apr 02, 2006 6:36 pm
Location: Jakarta

Re: Problems with: $mainframe->addCustomHeadTag();

Post by Zach Guffron » Thu May 24, 2007 1:08 pm

You can add a function in your component class,

Code: Select all

<?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: Select all

<?php loadStyle('sample'); ?>
It works for me...
~ Current work: ~ Jobless

bpatient
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 148
Joined: Thu Jul 20, 2006 7:15 am
Location: UK
Contact:

Re: Problems with: $mainframe->addCustomHeadTag();

Post by bpatient » Thu May 31, 2007 11:00 am

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: Select all

<?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


Locked

Return to “Joomla! 1.0 Coding”