Although you can do very much with TypoScript itself, it can sometimes be a much more flexible solution to include a PHP-script you write on your own. But you must understand and respect som circumstances. For example the caching system: When a page is shown with TYPO3 it's normally cached afterwards in the SQL-database. This is done to ensure a high performance when delivering the same page the next time. But this also means that you can only make custom code from your include files if you differ your output based on the same conditions that the template may include! Fx. you cannot just return browser-specific code to TypoScript if not the template also distinguish between the actual browsers. If you do, the cache will cache the page with the browser-specific HTML-code and the next hit by another browser will trigger the cache to return a wrong page. If the condition is correctly setup "another browser"-hit will instead render another page (which will also be cached but tagged with the other browser!) an the two browsers will receive different pages but still the pages will be cached.
Your script is included by a function, PHP_SCRIPT, inside the class "tslib_cObj" in the "tslib_content.php" script. Thereby your file is a part of this object (tslib_cObj) and function. This is why you must return all content in the variable "$content" and any TypoScript-configuration is available from the array "$conf" (it may not be set at all though so check it with is_array()!)
The array $conf contains the configuration for the PHP_SCRIPT cObject. Try debug($conf) to see the content printed out for debugging!
Return all content in this variable.
Remember, don't output anything (but debug code) in your script!
Because nothing is sent off to the browser before everything is rendered and returned to index_ts.php which originally set of the rendering process, you must ensure that there's no whitespace before and after your <?...?> tags in your include- or library-scripts!
Call the function $GLOBALS["TSFE"]->set_no_cache(), if you want to disable caching of the page. Call this during development! And call it, if the content you create may not be cached.
NOTE: If you make a syntax error in your script that keeps PHP from executing it, then the $GLOBALS["TSFE"]->set_no_cache() function is not executed and the page is cached! So in such situations, correct the error, clear the page-cache and try again. This is true only for PHP_SCRIPT and not PHP_SCRIPT_INT and PHP_SCRIPT_EXT which are rendered after the cached page!
Gets a content-object from the $conf-array. (See the casestory on how to use this!)
stdWrap's the content "value" due to the configuration of the array "properties".
There are some vars in the global object, TSFE, you might need to know about. These ARE ALL READ-ONLY!! (Read: Don't change them!). See the class tslib_fe for the full descriptions.
You access them like this example with “id”:$GLOBALS["TSFE"]->id
Var: | PHP-Type: | Description: | Default: |
|---|---|---|---|
id | int | The page id | |
type | int | The type | |
page | array | The pagerecord | |
fe_user | object | The current front-end user. Userrecord in $GLOBALS["TSFE"]->fe_user->user, if any login. | |
loginUser | boolean | Flag indicating that a front-end user is logged in. | 0 |
rootLine | array | The rootLine (all the way to tree root, not only the current site!). Current site root line is in $GLOBALS["TSFE"]->tmpl->rootLine | |
sys_page | object | The object with pagefunctions (object) See t3lib/page.php | |
gr_list | string (list) | The group list, sorted numerically. Group -1 = no login | |
beUserLogin | boolean | Flag that indicates if a Backend user is logged in! | 0 |