Code above document header

Discussion and education for beginner / novice programmers interested in embarking on the development process to take advantage of the extensible nature of the Joomla! CMS.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Forum rules
Post Reply
saltoricco
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Sat Nov 24, 2007 6:10 pm

Code above document header

Post by saltoricco » Thu Nov 29, 2007 1:38 am

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!

User avatar
ianmac
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 237
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: Code above document header

Post by ianmac » Thu Nov 29, 2007 2:27 am

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
Help test my Component XML Generator Tool!
http://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,1997/Itemid,35/
All feedback appreciated!

saltoricco
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Sat Nov 24, 2007 6:10 pm

Re: Code above document header

Post by saltoricco » Thu Nov 29, 2007 2:51 am

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

User avatar
ianmac
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 237
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: Code above document header

Post by ianmac » Thu Nov 29, 2007 3:14 am

Help test my Component XML Generator Tool!
http://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,1997/Itemid,35/
All feedback appreciated!

saltoricco
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Sat Nov 24, 2007 6:10 pm

Re: Code above document header

Post by saltoricco » Thu Nov 29, 2007 5:31 am

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

User avatar
CirTap
Joomla! Intern
Joomla! Intern
Posts: 73
Joined: Mon Dec 12, 2005 5:34 pm
Contact:

Re: Code above document header

Post by CirTap » Thu Nov 29, 2007 3:15 pm

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
You can have programs written fast, well, and cheap, but you only get to pick 2 ...

"I love deadlines. I like the whooshing sound they make as they fly by." Douglas Adams

User avatar
ianmac
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 237
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: Code above document header

Post by ianmac » Thu Nov 29, 2007 3:48 pm

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
Help test my Component XML Generator Tool!
http://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,1997/Itemid,35/
All feedback appreciated!

saltoricco
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Sat Nov 24, 2007 6:10 pm

Re: Code above document header

Post by saltoricco » Thu Nov 29, 2007 4:56 pm

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

Post Reply