[TYPO3] php script in <head> section

Christopher Torgalson bedlamhotel at gmail.com
Tue Sep 2 17:33:24 CEST 2008


Hi,

On 2-Sep-08, at 3:14 PM, Dennis Hoffland wrote:

> Dear List,
>
>
>
> I am trying to get the output from a php-script (a javascript to force
> frames) into the <head> section of the rendered website page. In the
> Typoscript setup I have the following lines:
>
>
>
> right.headerData.40 = PHP_SCRIPT
>
> right.headerData.40.file = fileadmin/scripts/frames.inc
>
>
>
> However, in this case the output is put at the top of the HTML page,  
> even
> before the <head> tag:
>
>
>
> if (parent.location.href == self.location.href) {
>
> window.location.href = "index.php";
>
> </script><!DOCTYPE html
>
>                PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
>
> <html>
>
> <head>
>
>                <meta http-equiv="Content-Type" content="text/html;
> charset=iso-8859-1" />
>
>
>
> <!--
>
>                This website is powered by TYPO3 - inspiring people to
> share!
>
>                TYPO3 is a free open source Content Management  
> Framework
> initially created by
>
> Kasper Skaarhoj and licensed under GNU/GPL.
>
>                TYPO3 is copyright 1998-2006 of Kasper Skaarhoj.  
> Extensions
> are copyright of their
>
> respective owners.
>
>                Information and contribution at http://typo3.com/ and
> http://typo3.org/
>
> -->
>
>
>
> The contents of my frames.inc file are:
>
>
>
> <?php
>
> print '<script language="JavaScript1.2" type="text/javascript">'."\n".
>     'if (parent.location.href == self.location.href) {'."\n".
>     'window.location.href =
> "index.php?id='.$GLOBALS[TSFE]->page[uid].'";'."\n".
>       '</script>';
>
> ?>
>
>
>
> Does anyone have a solution?

Use Typoscript. I see nothing in the php or javascript that requires  
that it be output by a PHP script at all (also, the script above is  
missing a "}"). Moreover, it's probably worthwhile to use typolink (as  
a matter of 'best practice'):

right.headerData = HTML
right.headerData {
	value {
		wrap = <script language="JavaScript1.2" type="text/javascript">if  
(parent.location.href==self.location.href)  
{window.location.href="|";}</script>
		typolink {
			parameter.data = page:uid
			returnLast = url
		}
	}
}

Not tested, but will work unless I've mis-remembered something :)

You might be wondering why you need to use typolink since it does add  
a bit of complexity, but it will a) be compatible with  
simulateStaticDocuments, RealUrl, CoolURI etc, and b) it will allow  
you to cope with any GET parameters in the url.

--
Christopher Torgalson
http://www.typo3apprentice.com/







More information about the TYPO3-english mailing list