Login / Status
developer.Resource
Home . Documentation . Document Library . Core Documentation
Sponsors
hosted by punkt.deTYPO3 and Open Source Magazine

2.3. Arrays (1,2,3,4...)

Sometimes you see properties listed as "1,2,3,4..." or "Array...". Another case is the datatype set to "array of strings".

Numerical arrays

It's neccessary to understand that TypoScript is not a language like javascript. TypoScript is more a list of definitions. The order of the definitions is set by the array numbers. In fact TypoScript is stored in a PHP array. But it's not true that you only store definitions with TypoScript. Because some 'definitions' call real PHP functions (like stdWrap). They can manipulate or even get data for output. That's why TypoScript is much more flexible and powerfull than simple HTML templates.

A good example of properties being a numerical array is the PAGE-object. The point of the pageobject is that it should return some content. In order for it to do so, you must attach some content objects (cObject) to it (see later). A simple cObject is "HTML" or "TEXT". They do the same (but not in the same way).

page = PAGE
page.typeNum=0
page.10 = TEXT
page.10.value = Hello world

This (defines a PAGE-object and) outputs the text "hello world" to the browser. The position "10" could have been 934290873 or any integer number. But why "10" then. For me it's tradition, but the point comes now, because if you would like to add some more content to the page, how do you do that? Well, you just add another cObject to the array!

page = PAGE
page.typeNum=0
page.10 = TEXT
page.10.value = Hello world
page.20 = TEXT
page.20.value = <BR>Are you listening?

Now why use "20"? Well, use whatever number greater than 10. But leave some "room" for new cObjects  between 10 and 20. You never know...

An important thing to understand is that the numerical arrays are always sorted. Non-numerical arrays never have any order attached to them, but numerical arrays have. The consequence of numerical arrays being sorted by their number is that:

page = PAGE
page.typeNum=0
page.10 = TEXT
page.10.value = Hello world
page.5 = TEXT
page.5.value = <BR>Are you listening?

... the line "<BR>Are you listening?" is now output before "Hello world" although they are defined in reversed order.

Normally you'll see TypoScript which is nicely coded in the numerical order, but that's just a good habit of the programmer as it's more readable that way.

String arrays

Whenever a string-array is defined (like the META object in TypoScript) it's because the keys (elements in the array) are unique and means something. The example with META is good. If you want to put META-tags "description" and "keywords" on your page, do this:

page = PAGE
page.typeNum=0
page.meta.REFRESH =  60; index.php?id=34
page.meta.DESCRIPTION = This is the description of the content in this document
page.meta.KEYWORDS = key, words, ...

This results in this HTML-code in the header of the site (which is very, very blank, if you try this in real life...)

<meta http-equiv="REFRESH" content="60; index.php?id=34">
<meta name="DESCRIPTION" content="This is the description of the content in this document">
<meta name="KEYWORDS" content="key, words, ...">



TYPO3 Core API

TSRef

TYPO3 Coding Guidelines