Page 1 of 1

Code above document header

Posted: Thu Nov 29, 2007 1:38 am
by saltoricco
Hi,

I'm looking for a way to add a PHP script block above the HTML document header. JDocument doesn't seem to allow for that. I'd like to do something like that in the view class:

Code: Select all

   $doc =& JFactory::getDocument();
    $doc->addPhpInclude('path/to/script.php');


The reason is I'm integrating an existing application into Joomla. It uses AJAX that is processed in the calling documents above the header to prevent any output. I'd like to keep the application as original as possible.

Thanks much!

Re: Code above document header

Posted: Thu Nov 29, 2007 2:27 am
by ianmac
Can you clarify exactly what you are trying to do?  It isn't exactly clear...

Is the PHP Script supposed to output something that should appear above the HTML document header?  If that is the case, then I would simply add a module position in the template and create a module that would produce the desired output.

If you are just trying to return results of an AJAX request, then you want to create a raw view.

Ian

Re: Code above document header

Posted: Thu Nov 29, 2007 2:51 am
by saltoricco
ianmac wrote:Can you clarify exactly what you are trying to do?  It isn't exactly clear...

Is the PHP Script supposed to output something that should appear above the HTML document header?  If that is the case, then I would simply add a module position in the template and create a module that would produce the desired output.

If you are just trying to return results of an AJAX request, then you want to create a raw view.

Ian

Hi Ian,

Thank you very much for your quick response! Yes, you assumed right, and it is AJAX requests that are to be handled by this script. Actually also other code that manipulates JavaScript (Google Map stuff). Both your suggestions sound like excellent ideas. I didn't know a module could be outside the html document.

I'm on my way, thanks again!

Holger

Re: Code above document header

Posted: Thu Nov 29, 2007 3:14 am
by ianmac

Re: Code above document header

Posted: Thu Nov 29, 2007 5:31 am
by saltoricco
ianmac wrote:Take a look at this thread...http://forum.joomla.org/index.php/topic,217394.0.html

Uh, yes Ian, that raw view mode is very handy. Thanks again!!

Holger

Re: Code above document header

Posted: Thu Nov 29, 2007 3:15 pm
by CirTap
Hi,

you're aware that the templates *are* PHP code, right?
You can put any sort of php code anywhere you want. To include another file, simply use


...


Not sure what you want to appear/happen before the html tag; some header() maybe, or a nasty XML prolog, but that's about all I can think of.

Note that all the processing of templates is encapsulated in various class methods and functions.

Have fun,
CirTap

Re: Code above document header

Posted: Thu Nov 29, 2007 3:48 pm
by ianmac
Hey CirTap,

I think he wanted code above the HTML header that would suppress the stuff below it from being displayed...  not certain though...

Ian

Re: Code above document header

Posted: Thu Nov 29, 2007 4:56 pm
by saltoricco
CirTap wrote:Hi,

you're aware that the templates *are* PHP code, right? ...

Thanks, CirTap.

I'm a Joomla n00b, so that probably explains most of it.

Ian is right, I wanted the PHP code block above the HTML document. Maybe we're talking about two different templates, the Joomla one and the one from the component.

An example where code above HTML comes in handy is a Google Map page. I load markers from the database and generate JavaScript to display them, along with some AJAX stuff for edit forms that Google Maps shows in the info windows. The list of markers depends on HTML GET parameters (i.e. "show all markers in Alabama"). Currently, I load the PHP to generate the JavaScript through a PHP file that's included with a