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

5.4. Simplified TypoScript Example

Let's take a moment and walk through a simple TypoScript example, using the SMS Resource Type - Downloadable File. For

Assume this is the current Record that is being processed by TYPO3, truncated for simplicity:

Example Downloadable File Record

title

Sermon Guide - 12/31/07

file

sermon_guide1.pdf,sermon_guide2.pdf

(There are two files attached to this record, sermon_guide1.pdf, and sermon_guide2.pdf)

   1: downloadfile = TEXT

   2: downloadfile {
   3:   field = title
   4:   typolink {
   5:           parameter = uploads/tx_wecsermons/{current:1}
   6:           parameter {
   7:                   setCurrent.field = file
   8:                   setCurrent.listNum = 0
   9:                   insertData = 1
  10:           }
  11:   }

  12: }

Text 2: Simplified TypoScript Example

Line 1: Define downloadfile  as a TEXT cObject. This causes any resource of this type to be rendered as simple text. See TEXT cObject of TypoScript Reference Document, TSRef section 8.3.

Line 3: Setting the field property to the value of title sets the output of downloadfile to the value stored in the title field of the current record. See field property of stdWrap, in TSRef section 5.1.

Line 4: Define typolink so that  the text output is wrapped in an HTML <a href></a> link, creating a clickable link. See typolink function in TSRef document, section 5.8.

Line 5: Set the typolink parameter to uploads/tx_wecsermons/{current:1}. Here, {current:1} is a variable that will be replaced during execution. See getText data type in TSRef section 2.2.

Line 7: setCurrent causes the current variable to be assigned the value stored in the file field of the record. current is essentially a temporary storage area where you can store content and manipulate it before assigning it to the actual output. See setCurrent property of the stdWrap function in TSRef section 5.1, and field property in the same section.

Line 8: The listNum property is set to 0, specifying an index key that is used to select one value from a comma separated list. In this case the file field is a comma separated list of filenames, and the index starts at 0 for the first item, i.e. Indexes 0,1,2,3. An index value of 2 selects the third item in the comma separated list. See listNum property of stdWrap, in TSRef section 5.1.

Line 9: Setting the insertData propery to 1 specifies that the parameter property value should be searched for {} brackets which denote variables, and any of these should be replaced by actual data. See insertData property of stdWrap, in TSRef section 5.1.

Now lets step through the execution process watching as each line is executed in order. Notice how the HTML output of the downloadfile cObject changes, and how the current variable is assigned a value, modified, and ultimately merged into the ouput.

Line 1

output

Line 3

output

Sermon Guide – 12/31/07

Line 5

output

<a href="uploads/tx_wecsermons/{current:1}">Sermon Guide – 12/31/07</a>

Line 7

output

<a href="uploads/tx_wecsermons/{current:1}">Sermon Guide – 12/31/07</a>

current

sermon_guide1.pdf,sermon_guide2.pdf

Line 8

output

<a href="uploads/tx_wecsermons/{current:1}">Sermon Guide – 12/31/07</a>

current

sermon_guide1.pdf

Line 9

output

<a href="uploads/tx_wecsermons/sermon_guide1.pdf">Sermon Guide – 12/31/07</a>

current

sermon_guide1.pdf