[TYPO3-dev] Coding Guidelines for TypoScript

Sebastian Michaelsen sebastian.gebhard at gmail.com
Sat Aug 14 12:05:05 CEST 2010


Should we add some rules for TypoScript to the CGL? css_styles_content has a lot of TS, it would be 
good to have it consistent.

Here is how I try to keep my TS consistent and good readable:

1. When to use Brackets
Use a Bracket whereever you would otherwise have 3 successive lines of "objectpath."
Example (taken from css_styled content):

# Currently in csc (wrong!)
lib.parseFunc_RTE {
   nonTypoTagStdWrap.HTMLparser = 1
   nonTypoTagStdWrap.HTMLparser {
     keepNonMatchedTags = 1
     htmlSpecialChars = 2
   }
}

# "HTMLparser" does not need an indented block, because only 2 properties
# of it are used. When removing the block, you'll get 3 times "nonTypoTagStdWrap."
# which needs an indentation then.
lib.parseFunc_RTE {
   nonTypoTagStdWrap {
     HTMLparser = 1
     HTMLparser.keepNonMatchedTags = 1
     HTMLparser.htmlSpecialChars = 2
   }
}


2. Brackets and Whitespace
There has to be one space between the object path and the opening bracket.
The following lines have to be indented by two spaces until the closing bracket, which is outdented 
again.


3. Order of stdWrap properties
When using stdWrap properties they should be ordered like they are executed. When you write your TS, 
you have to be aware of this anyway.

Example (taken from css_styled_content):

# Currently in csc (wrong!)
lib.stdheader {
   #...
   10.1 = TEXT
   10.1.current = 1
   10.1.insertData = 1
   10.1.fontTag = <h1{register:headerStyle}{register:headerClass}>|</h1>
}

# The current order is confusing. First the "current" value is taken, wrapped into a "fontTag" and # 
then markers are replaced by "insertData". Therefore it should be like:
lib.stdheader {
   #...
   10{
     1 = TEXT
     1 {
       current = 1
       fontTag = <h1{register:headerStyle}{register:headerClass}>|</h1>
       insertData = 1
     }
   }
}


Oppinions?




More information about the TYPO3-dev mailing list