[TYPO3] How to add php code into a page?

bernd wilke xoonsji02 at sneakemail.com
Fri May 30 13:46:14 CEST 2008


on Fri, 30 May 2008 07:44:59 +0800, Ronald Wiplinger wrote:

> I would like to add these lines into a page:
> 
> <?php
> $dday = mktime(0, 0, 0, 3, 29, 2001); $diff = time() -$dday;
> $days = $diff / 86400;
> printf( "(%d day%s young)", $days, $days == 1 ? "" :"s"); ?>
> 
> It is just a calculation of days between today and March 29, 2001.
> 
> I added above code into a pagecontent of type HTML.
> 
> What would be the correct way?

build your own extension.
use the kickstarter and create an extension with one FE-Plugin and you 
will get one file with dummy-code.
the file will be something like:
typo3conf/ext/yourextkey/pi1/class.tx_yourextkey_pi1.php

instead of echo/.. you have to store your output to the return-variable 
$content

then you can include the plugin as normal content to your page

to make your extension more flexible you can define the basedate 
configurable in typoscript and access this from your extension:

typoscript:
plugin.tx_yourextkey_pi1.base {
	year = 2001
	month = 3
	day = 29
}

PHP in main of extension:
	$year  = $conf['base.']['year'];
	$month = $conf['base.']['month'];
	$day   = $conf['base.']['day'];


bernd
-- 
http://www.pi-phi.de/t3v4/cheatsheet.html


More information about the TYPO3-english mailing list