[TYPO3-english] TS Code Reuse

bernd wilke t3ng at bernd-wilke.net
Thu Mar 26 08:42:54 CET 2015

Am 26.03.15 um 04:34 schrieb Scotty C:
> Hi again,
> In my ongoing pursuit of defeating the TS monster, I have (hopefully) one more question and then I'll be good for a while ;-)
> I want to cleanup/minimize/optimize my code
> I have created a large chunk of TS, let's say:
> Constants:
title1 = <h1>Title1</h1>
title2 = <h1>Title2</h1>

my recommandation: don't mix values and wraps
you may define constants for vlaues and you may define constants for 
wraps, but distinct the usage:

title1= Title 1
title2= Title 2
titleWrap1 = <h1>|</h1>
titleWrap2 = <h2>|</h2>

> Setup:
temp.myFunc1 = TEXT
temp.myFunc1 {
     .... {$title1}
> temp.myFunc2 = TEXT
temp.myFunc2 {
     .... {$title2}
> myFunc1 and myFunc2 are exactly the same, except that myFunc1 references title1 and myFunc2 references title2. Is there any way to reuse/merge the code and then just pass the constant, kind of like a function in a programming language? I know TS is not a programming language, but I'm hoping this can be done - something like
> temp.myFunc($title) = TEXT
temp.myFunc {
$theTitle = $title
> marks.TEST1 < temp.myFunc({$title1})
marks.TEST2 < temp.myFunc({$title2})

there are no functions with parameters in typoscript
but you may use your own individual values for each usage

temp.something = <OBJECT>
you define a temporary object definition you may use afterwards.
maybe like:
page.10.20 < temp.something
then all your temp.something-definition is copied to this place.
you also may use it at a different place:
page.10.40 < temp.something
and both have nothing in common. It are copies and not references!

afterwards you can individualize it:
page.10.20.value = {$title1}
page.10.40.value = {$title2}

temp.header = COA
temp.header {
	10 = TEXT
	10.value = default headline, which will be replaced afterwards
	10.wrap = <h1>|</h1>

	20 = TEXT
	20.data = date : d-m-y
	20.wrap = <span class="date">info from:|</span>

page.10.20 < temp.header
page.10.20.10.value = headline in Column left

page.10.40 < temp.header
page.10.40.10.value = headline in Column right

or (taking definitions of above in acount)
page.10.20 < temp.header
page.10.20.10.value = {$title1}
page.10.20.10.wrap = {$titleWrap1}

page.10.40 < temp.header
page.10.40.10.value = {$title2}
page.10.40.10.wrap = {$titleWrap2}


More information about the TYPO3-english mailing list