2. Obstacles to Seeing the
Utility of TypoScript
• Unfashionable:
TypoScript represents
configuration over
convention for many
developers
• Challenging: too much
like code for many
beginners
3. Attempts to Address These
Obstacles
• Object Oriented TypoScript - circa 2005 as
an attempt to recast TypoScript for
developers
• Template Auto-parser and TemplaVoila as
ways to avoid having to learn too much
TypoScript
4. Why TypoScript Made
Me Worry
• Idiosyncratic naming conventions
• aTagParams or ATagParams?
• stripHtml vs. removeBadHTML
• Underscores or CamelCase?
• Property positions not always intuitive
• IMAGE.file.width or IMAGE.width?
5. Why TypoScript Made
Me Worry
• Learning to Navigate the TSREF is
Challenging
• Because properties can be functions,
data types, or even other cObj types,
readers make many passes through the
TSREF to find what they seek
• Improved linking in the TSREF would go
a long way - CIC volunteers to help!
6. Why TypoScript Made
Me Worry
• No clear set of TypoScript Best Practices, as
there is for TYPO3 PHP code
• Lack of best practices leads to many
interpretations of TypoScript
• Many interpretations means users often
aren’t able to take knowledge gained from
the TSREF or from one extension and apply
it to a new extension
13. From TypoScript to Output
TypoScript: $conf Database Record
email_stdWrap.wrap Email: | email zach@cic.com
PLUGIN
INSTANCE
date_stdWrap.wrap Date: | date 4/1/2009
author_stdWrap.wrap Author: | author Zach Davis
Marker Array
Email:
field_email
zach@cic.com
Date:
field_date
4/1/2009
Author: Zach
field_author
Davis
14. It works, and it’s worked for a
long time.
But we can do better.
15. Do we really need a new
approach?
• Limiting rendering of a marker to stdWrap
is unnecessarily limiting. Why ignore the
wealth of functionality in tslib_cObj?
• What if I need a custom field and a
corresponding custom marker? Do I modify
the PHP? Do I XCLASS it? Hope for a
hook?
16. Do we really need a new
approach?
• Certainly, some TypoScript contains control
logic (how many records to list, which view
to display, etc).
• However, a lot of TypoScript is really
presentation logic, and as such should not
be hardcoded into the extension PHP class.
17. Do we really need a new
approach?
• Yes! Let’s avoid idiosyncratic TypoScript
properties.
• If each marker has stdWrap available as
stdWrap, for example, users don’t need to
remember extension-specific properties.
23. The Solution!
$cObj = t3lib_div::makeInstance('tslib_cObj');
markers {
foreach($records as $row) {
image = IMAGE
$cObj->start($row,'tx_dam');
title = TEXT
foreach($markerConf as $key => $value) {
}
if(is_string($value)) {
$type = $value;
$conf = $markerConf[$key.'.'];
$markerValues['###'.$key.'###'] =
$cObj->cObjGetSingle($type,$conf);
}
}
}
24. ONE ONE ONE
FIELD PROPERTY MARKER
Database Record TypoScript: $conf Marker Array
Email:
email zach@cic.com email_stdWrap.wrap Email: | field_email
zach@cic.com
Date:
date 4/1/2009 date_stdWrap.wrap Date: | field_date
4/1/2009
Author: Zach
author Zach Davis author_stdWrap.wrap Author: | field_author
Davis
25. email = TEXT
wrap Email: |
typolink.parameter.field email
Database Record Marker Array
date = TEXT
email zach@cic.com field_email Email: zach@cic.com
wrap Date: |
Date:
date 4/1/2009 field_date
4/1/2009
stdWrap.strftime %D %T
author_uid 29 field_author Author: Zach Davis
author_name Zach Davis
author = TEXT
wrap Author: |
field author_name
typolink.parameter 10
typolink.ATagParams &tx_myext_pi1[author]={field:author_uid}
typolink.ATagParams.
1
insertData
26. The Solution!
$cObj = t3lib_div::makeInstance('tslib_cObj');
markers {
foreach($records as $row) {
image = IMAGE
$cObj->start($row,'tx_dam');
title = TEXT
foreach($markerConf as $key => $value) {
}
if(is_string($value)) {
$type = $value;
$conf = $markerConf[$key.'.'];
$markerValues['###'.$key.'###'] =
$cObj->cObjGetSingle($type,$conf);
}
}
}
27. If you’re creating TypoScript
templates, you’re probably
doing this already.
lib.pageTitle = TEXT
lib.pageTitle.field = title
28. The Solution!
$cObj = t3lib_div::makeInstance('tslib_cObj');
markers {
foreach($records as $row) {
image = IMAGE
$cObj->start($row,'tx_dam');
title = TEXT
foreach($markerConf as $key => $value) {
}
if(is_string($value)) {
$type = $value;
$conf = $markerConf[$key.'.'];
$markerValues['###'.$key.'###'] =
$cObj->cObjGetSingle($type,$conf);
}
}
}
30. ...when it can look like this?
views {
single {
markers {
title = TEXT
title.wrap = <h1>|</h1>
title.field = title
body = TEXT
body.parseFunc < lib.parseFunc_RTE
body.field = bodytext
}
}
}
31. ...when it can look like this?
views {
single {
markers {
title = TEXT
title.wrap = <h1>|</h1>
title.field = title
body = TEXT
body.parseFunc < lib.parseFunc_RTE
body.field = bodytext
image = IMAGE
image.file.import.field = image
}
}
}
32. ...when it can look like this?
views {
single {
markers {
title = TEXT
title.wrap = <h1>|</h1>
title.field = title
title.if.isTrue.field = title
body = TEXT
body.parseFunc < lib.parseFunc_RTE
body.field = bodytext
image = IMAGE
image.file.import.field = image
isFriendIcon = USER_INT
isFriendIcon.userFunc = myClass->method
}
}
}