TYPO3Buddy is on FacebookTYPO3Buddy is on Twitter

Extension development: variables

Extension configuration

General variables used by the extension for the entire website can be stored in the ext_conf_template.txt file (which won't be created by the kickstarter), and will be placed in the extension folder (/typo3conf/ext/extension/). The values in this file are default values.

The ext_conf_template.txt file looks like something like this:

# cat=basic; type=int+; label=Page ID members : Page ID where members are stored
memberFolder =

# cat=basic; type=string; label=Calendar website : Website address of the calendar
extensionWebsite =

# cat=basic/enable; type=boolean; label=Enable images : Check this to enable images in RTE
enableImages = 0

# cat=basic; type=color; label=Text color : The HTML text color code will be used
extColor = black

These variables can be changed in the extension manager. Click on the extension and choose "Information" from the pull down menu on top of the screen if necessary. Change values. When you click on "Update", the values will be stored in the /typo3conf/localconf.php file.

A comment in this file is not just a comment, it defines the category/subcategory, data type, title and description of each variable/value pair. Title and description are both in the label part, separated by a colon (:).

To retrieve these variables in your PHP script use this:

$this->confArray = unserialize($GLOBALS["TYPO3_CONF_VARS"]["EXT"]["extConf"][$this->extKey]);

The variables stated above will be stored in the array, for example $this->confArray['memberFolder']


Of course, when you need a variable of which it's value depends on the page it's on, you'll have to store the variable in a typoscript template, and put that typoscript template on the page where you need it.

In TYPO3, on the page with your extension, you'll place a new content element (template type). In the setup part you'll put something like the following text, where "extension_key" obviously needs to be replaced with the key of your extension (declared as $extKey in your extension class):

plugin.extension_key {
    show_submit = 1
    submit_text = Submit

To retrieve these values you can put this code in the main() function of the extension:

global $TSFE;
$defaultConf = array(
foreach ($defaultConf as $key => $defaultValue) {
    if (isset($TSFE->tmpl->setup['plugin.'][$this->extKey.'.'][$key])) {
        $this->{$key} = $TSFE->tmpl->setup['plugin.'][$this->extKey.'.'][$key];
    } else {
        $this->{$key} = $defaultValue;
echo $this->show_submit; // shows 1 (from typoscript)

PHP variables

Some handy PHP stuff which I use often when I create a new extension:

$User = $GLOBALS['TSFE']->fe_user->user; // array with data from logged in user
$Page = $GLOBALS['TSFE']->page; // array with data from the current page
$PageID = (int)$GLOBALS['TSFE']->id;
$ExtPath = t3lib_extMgm::siteRelPath($this->extKey); // path from DOCUMENT_ROOT

$Target = '_top';
$Params = array('someid'=>1,'otherid'=>3);
$Url = $this->pi_getPageLink($PageID,$Target,$Params); // works well with realurl extension

More info on links: http://typo3.org/development/articles/using-links-in-frontend-plugins/

The TYPO3Buddy website is a tutorial to rebuild the TYPO3Buddy website from scratch. You can choose from a TYPO3 Fluid tutorial and a TYPO3 Templavoila tutorial. You'll build TYPO3 websites like you've done so for years!