[TYPO3] How to add php code into a page?
Dmitry Dulepov [typo3]
dmitry at typo3.org
Fri May 30 13:03:59 CEST 2008
Hi!
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?
If you can include it from TypoScript, the correct way is to create a PHP file named user_datediff.php with the following content:
<?php
function user_datediff() {
$dday = mktime(0, 0, 0, 3, 29, 2001);
$diff = time() - $dday;
$days = $diff / 86400;
return sprintf('(%d day%s young)', $days, $days == 1 ? '' : 's');
}
?>
The in TypoScript:
includeLibs.user_datediff = fileadmin/user_datediff.php
page.100 = USER
page.100.userFunc = user_datediff
If you want to use it as content element, you have to make a TYPO3 extension.
--
Dmitry Dulepov
TYPO3 core team
Learn more about TYPO3! Read http://typo3bloke.net/
Skype: callto:liels_bugs but go straight to business!
More information about the TYPO3-english
mailing list