Book Image

Mastering TypoScript: TYPO3 Website, Template, and Extension Development

Book Image

Mastering TypoScript: TYPO3 Website, Template, and Extension Development

Overview of this book

Free, open-source, flexible, and scalable, TYPO3 is one of the most powerful PHP content management systems. It is well suited for creating intranets and extranets for the enterprise. While providing an easy-to-use web interface for non-technical authors and editors of content, its messaging and workflow system enable shared authoring and collaboration. TYPO3 provides flexible and powerful interfaces for both content editors and administrators, giving them full control of the core aspects the system. However for developers who need to customize the system, TYPO3 offers a powerful configuration language called TypoScript. Good knowledge of TypoScript is really a prerequisite for implementing complex applications with TYPO3 and gives developers full control over the configuration of TYPO3 and its template engine. TypoScript enables the complete output template to be created and manipulated, giving you full control over the layout of the site. TypoScript also allows you to integrate dynamic contents, JavaScript-based menus, Flash, Graphics, etc. with ease. You have maximum control over the design of the website and can control all options that would otherwise be addressed by HTML-simple text output, formatting, and much more. TypoScript also allows you to generate graphics at run time and display different content dynamically.
Table of Contents (19 chapters)
Mastering TypoScript: TYPO3 Website, Template, and Extension Development
Credits
About the Author
Preface

TypoScript and PHP


We have already pointed out that TypoScript is programmed in PHP. However, you do not have to know PHP syntax to be able to work with TypoScript; but knowledge of PHP is definitely an advantage. You can, for example, easily import information from the PHP class files using appropriate objects and values. The following example will show how this works.

Anyone who wants to know more about the structure and the development (from a programming point of view) of TypoScript should take a look at the tslib directory. It contains the PHP classes that control TypoScript.

For a better understanding open the file typo3/sysext/cms/tslib/class.tslib_content.php. You will find numerous PHP functions in it. We will concentrate on the CTABLE() function.

function CTABLE ($conf)
{ $controlTable = t3lib_div::makeInstance('tslib_controlTable'); if ($conf['tableParams'])
{ $controlTable->tableParams = $conf['tableParams']; } // loads the pagecontent $controlTable->contentW = $conf['cWidth']; // loads the menues if any if (is_array($conf['c.']))
{ $controlTable->content = $this->cObjGet($conf['c.'],'c.');
$controlTable->contentTDparams =isset($conf['c.'] ['TDParams']) ? $conf['c.']['TDParams'] : 'valign="top"'; } if (is_array($conf['lm.']))
{ $controlTable->lm = $this->cObjGet($conf['lm.'],'lm.'); $controlTable->lmTDparams = isset($conf['lm.'] ['TDParams']) ? $conf['lm.']['TDParams'] : 'valign="top"'; } if (is_array($conf['tm.']))
{ $controlTable->tm = $this->cObjGet($conf['tm.'],'tm.'); $controlTable->tmTDparams = isset($conf['tm.'] ['TDParams']) ? $conf['tm.']['TDParams'] : 'valign="top"'; } if (is_array($conf['rm.']))
{ $controlTable->rm = $this->cObjGet($conf['rm.'],'rm.'); $controlTable->rmTDparams = isset($conf['rm.']
['TDParams']) ? $conf['rm.']['TDParams'] : 'valign="top"'; } if (is_array($conf['bm.']))
{ $controlTable->bm = $this->cObjGet($conf['bm.'],'bm.'); $controlTable->bmTDparams = isset($conf['bm.'] ['TDParams']) ? $conf['bm.']['TDParams'] : 'valign="top"'; }
return $controlTable->start($conf['offset'], $conf['cMargins']); }

Thanks to this function, elements can easily be positioned with the help of a table. What does this mean for TypoScript? To understand this take a look at the following syntax, which uses the Content Object (cObject) CTABLE:

page = PAGE page.10.marks.TABLE = CTABLE page.10.marks.TABLE { tableParams = width="800" border="0" cellpadding="3" cellspacing="0" offset = 0,0,0,0,0 cMargins = 15,15,15,15 rm.TDParams = width="100" valign="bottom" tm.TDParams = width="300" valign="bottom" lm.TDParams = width="300" valign="bottom" bm.TDParams = width="100" valign="bottom" c.TDParams = width=80% c.10 < styles.content.get tm.10 = HMENU tm.10.1 = TMENU tm.10.1 { NO.allWrap = | target = page }
}

Using page.10.marks.TABLE, a new TypoScript object of the CTABLE type is defined. Using TypoScript, the remaining lines define the look and the content of the table. You are surely familiar with the HTML layout attributes; TypoScript's own attributes such as HMENU etc. will be shown later. Note that you will need templates and placeholders to get this example to work. More information on these can be found in Chapter 4 and Chapter 5. The output of this example is shown below:

If you want to work more closely with the PHP functions, take one function after another and experiment with it. You will gradually understand how the meshing between TypoScript and PHP works. At the same time you also have an opportunity to learn about the weaknesses of TypoScript. Each TypoScript object can only deliver what the programmer has designed into the respective function (except when you develop your own functions).

The core of TypoScript is the typo3/sysext/cms/tslib/index_ts.php file. It charts the information about the template datasets of the website tree. How this works is shown by the following TypoScript:

page = PAGE page.typoeNum = 0 mybicycle.color = blue mybicycle.size = 26

This syntax creates the TypoScript object mybicycle. You assign the properties color and size to the mybicycle object. These two properties in turn are assigned the following values: color becomes blue and size gets the value 26. In the TypoScript Object Browser you will see objects, properties, and values represented as follows:

PHP can also be used directly in TYPO3; we will cover more about this later.