Mastering “split” in Typoscript

March 16, 2012  |  No Comments
featuredimage_typo3

Recently I had to face a complicated challenge in typo3.

I was building module for the WE DO agency, where it had to show images of the team member in color, in B&W, a string with their name and another string with their job position.

This means 4 different fields in the tt_contents table. The images where all separated with “,” in the field “media” and “media2″ (a custom field), and the text strings where stored in the fields “altText” and “imagecaptions”, separated by the separator-character (literally redundancy, I know).

How to display all this information with Typoscript? One way was to use listNum and the copy the object manually over and over, but this was not efficient. The real solution was using the split function. This is how it works.

15 = TEXT
15{
    wrap = <div class="team-gallery clearfix">|</div>
    field = media
    split{
        token = ,
        cObjNum = 1
 
        1.cObject = COA
        1.cObject{
            wrap = <div class="team-member">|</div>
            10 = IMAGE
            10.file{
                width = 200
                height = 200
                import = uploads/media/
                import{
                    current = 1
                }
            }
 
            20 = IMAGE
            20.params = class="bw"
            20.file{
                width = 200
                height = 200
                import = uploads/tx_wedoteam/
                import{
                    field = media2
                    listNum.stdWrap.data = register:SPLIT_COUNT
                }
            }
 
            30 = COA
            30{
                wrap = <div class="bio">|</div>
                10 = TEXT
                10{
                    wrap = <span class="name">|</span>
                    field = imagecaption
                    listNum.splitChar = 10
                    listNum.stdWrap.data = register:SPLIT_COUNT
                }
 
                20 = TEXT
                20{
                    field = altText
                    listNum.splitChar = 10
                    listNum.stdWrap.data = register:SPLIT_COUNT
                    wrap = <span class="info">|</span>
                }
            }
        }
    }
}

Thanks to the Typo3 Community for their support to find the answer :)



Leave a Reply

Your email address will not be published. Required fields are marked *