[TYPO3-english] TS Code Reuse
Jo Hasenau
info at cybercraft.de
Tue Apr 7 11:16:46 CEST 2015
> 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})
Just for the record: There are two options to reuse a predefined piece
of TS code in another place - copy and reference.
While a copy will always create the whole predefined array of keys,
values and sub arrays adding up to the number of lines in the whole TSFE
array, referencing will just set a pointer and keep the code lean and
speed up parsing.
10 < lib.whatever will create a copy
10 =< lib.whatever will set a pointer
So as long as you don't have to remove values with the > operator, and
each time you just want to reuse the same piece of code again and again,
it makes sense to go for a reference.
To be able to track the code in the TypoScript Object Browser you should
go for lib.whatever instead of temp.whatever then, since temp will be
removed after parsing, while lib will be visible.
Depending on the amount of TypoScript you are using and the number of
loops that are making use of the TypoScript array, you might even solve
problems with memory limits by switching from copy to reference.
Just my 2 cents
Joey
--
Diversity:
Die Kunst zusammen unabhängig zu denken
The art of thinking independently together.
--
Facebook: https://www.facebook.com/johasenau
Twitter: http://twitter.com/bunnyfield
Xing: http://contact.cybercraft.de
TYPO3 cookbook (2nd edition): http://www.typo3experts.com
More information about the TYPO3-english
mailing list