Joomla!
http://forum.joomla.org/

Problems with: $mainframe->addCustomHeadTag();
http://forum.joomla.org/viewtopic.php?f=126&t=139615
Page 1 of 1

Author:  acalderon [ Thu Feb 08, 2007 11:45 pm ]
Post subject:  Problems with: $mainframe->addCustomHeadTag();

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();?
??? :(

Author:  Hackwar [ Fri Feb 09, 2007 12:41 am ]
Post subject:  Re: Problems with: $mainframe->addCustomHeadTag();

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

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

Author:  jlleblanc [ Fri Feb 09, 2007 4:08 am ]
Post subject:  Re: Problems with: $mainframe->addCustomHeadTag();

Did you call
Code:
global $mainframe
in your code before calling the addCustomHeadTag() function or did you pass $mainframe into a function?

Author:  acalderon [ Fri Feb 09, 2007 9:18 am ]
Post subject:  Re: Problems with: $mainframe->addCustomHeadTag();

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.

Author:  jlleblanc [ Sat Feb 10, 2007 2:05 am ]
Post subject:  Re: Problems with: $mainframe->addCustomHeadTag();

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?

Author:  turokthemighty [ Mon Feb 12, 2007 3:48 am ]
Post subject:  Re: Problems with: $mainframe->addCustomHeadTag();

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

Author:  acalderon [ Mon Feb 12, 2007 4:18 am ]
Post subject:  Re: Problems with: $mainframe->addCustomHeadTag();

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.

Author:  turokthemighty [ Mon Feb 12, 2007 4:23 am ]
Post subject:  Re: Problems with: $mainframe->addCustomHeadTag();

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

Author:  bestofrisk [ Sat May 05, 2007 9:32 am ]
Post subject:  Re: Problems with: $mainframe->addCustomHeadTag();

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

Author:  acalderon [ Tue May 08, 2007 2:48 am ]
Post subject:  Re: Problems with: $mainframe->addCustomHeadTag();

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.

Author:  Zach Guffron [ Thu May 24, 2007 1:08 pm ]
Post subject:  Re: Problems with: $mainframe->addCustomHeadTag();

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

Author:  bpatient [ Thu May 31, 2007 11:00 am ]
Post subject:  Re: Problems with: $mainframe->addCustomHeadTag();

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

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/