

The CONTENT object is in TYPO3 used to read something form a database table. It is especially usefull if you want to format the content in a special way, eg. as parameters for a flash movie.
In the following article i will try to explain with examples the basics of the CONTENT object, but i will also have a look at some more advanced possibilities.
Lets start with a simple example:
Read max. 10 contents from the right column of the current page. If there is a image show it too.
temp.right_content=CONTENT temp.right_content{ # The table from which is beeing read ( the only one allowed are "pages" or tables with the prefix "tt_","tx_","ttx_","fe_" or "user_") table=tt_content # wrap the whole element wrap=| # the SQL-Query select{ # Set the language field languageField=sys_language_uid # limit 10 entries max=10 # selectFields is optional, the default value is *. When looking at perfomance i recomand to set the used fields here. selectFields=image,header # The where clausel, in this case colPos=2 for the right column where=colPos=2 } renderObj=COA renderObj{ # create a IMAGE object 5=IMAGE 5{ # only output it if not empty required=1 wrap=| file.import=uploads/pics/ file.import.field=image file.width=100 file.height=100 } # The header of the content element 10=TEXT 10{ required=1 wrap=| field=header } # Following TEXT ement would output all the available fields, that means if you dont set selectFields all of the available database fields are outputted #20=TEXT #20.data = debug:data } }
Substantially the CONTENT element contains 2 parts: the select part and the renderObj. In the select part the SQL-query is defined and in the renderObj you define which fields are how formatted.
The most flexible way is to define the renderObj as a COA, because there you can insert as many other cObjects (TEXT,IMAGE,..) as you want.
CONTENT objects can also be nested, just define in the renderObj a other CONTENT object. This second CONTENT object can now access the fields selected with CONTENT element before.
Following sample prints the header of the page, reads its subpages and prints the first content element with image and creates a link to the page. Also the bodytext is being outputted and cutted after 20 chars.
temp.sectionMenu=COA temp.sectionMenu{ 5=TEXT # Title of the page 5.data=leveltitle:-2 5.wrap= <h1>|</h1> # first CONTENT object for the header 10=CONTENT 10{ stdWrap.wrap=| table=pages select.orderBy=sorting # If this element is inserted as sitemap, consider the startingpoint select.pidInList.if.isTrue.field=pages select.pidInList.field=pages renderObj=COA renderObj{ stdWrap.wrap=| # Title and link to the page 5=TEXT 5.wrap=<b>|</b> 5.field=title 5.typolink.parameter.field=uid # 2. CONTENT object for reading the first content element 10=CONTENT 10{ table=tt_content select.pidInList.field=uid select.where=colPos=0 select.orderBy=sorting select.max=1 renderObj=COA #read the image renderObj.2=IMAGE renderObj.2{ wrap=| # show it only if inserted stdWrap.if.isTrue.field=image stdWrap.typolink.parameter.field=pid file.import=uploads/pics/ file.import.field=image file.width=100 file.height=100 } #read the bodytext renderObj.10=TEXT renderObj.10{ field=bodytext #cut after 20 chars, keep whole words if possible crop=20 | ... |1 } } # more link 20=TEXT 20.wrap=<b>|</b> 20.value=[more] 20.typolink.parameter.field=uid } } }
We all know optionSplit from menues, but how is this applied to CONTENT objects?
If we are looking in the TSREF we see that a lot of menu properties have a +opionSplit, but no properties in other objects have it.
This can be solve with the split function.
Just append to every element that should be outputted with optionSplit a placeholder, and afterward replace this placeholder with split.
Following samples prints the header and the text of the content elements of the actual page in the following form:
<div class="first">first </div> <div class="second">second</div> <div class="third">third</div> <div class="middle1">middle 1</div> <div class="middle2">middle 2</div> <div class="middle1">middle 1</div> <div class="middle2">middle 2</div> <div class="last">last one</div>
Typoscript:
#Create the CONTENT object temp.contentToSplit=CONTENT temp.contentToSplit{ table=tt_content renderObj=COA renderObj{ # Append to every element ###SPLITTER### stdWrap.outerWrap = |###SPLITTER### 10=TEXT 10.field=header 10.wrap=|<br> 20=TEXT 20.field=bodytext 20.wrap=|<br> } } temp.content = COA temp.content { # Copy the readet content here 10 < temp.contentToSplit stdWrap.split { # replace ###SPLITTER### with the split option token = ###SPLITTER### # the order is beeing defined in the normal optionSplit style cObjNum = 1 || 2 || 3 |*| 4 || 5 |*| 6 || 7 # define the wraps on every position 1.current = 1 1.wrap = <div class="first">|</div> 2.current = 1 2.wrap = <div class="second">|</div> 3.current = 1 3.wrap = <div class="third">|</div> 4.current = 1 4.wrap = <div class="middle1">|</div> 5.current = 1 5.wrap = <div class="middle2">|</div> 6.wrap = <div class="last">|</div> 6.current = 1 # leave last splitter empty 7.current = 1 } }
You can apply this approach also with the normal styles.content.get
Sample:
#set the placeholder after everey content element tt_content.stdWrap.outerWrap = |###SPLITTER### temp.content = COA temp.content { 10 < styles.content.get stdWrap.split { token = ###SPLITTER### cObjNum = 1 || 2 || 3 |*| 4 || 5 |*| 6 || 7 1.current = 1 1.wrap = <div class="first">|</div> 2.current = 1 2.wrap = <div class="second">|</div> 3.current = 1 3.wrap = <div class="third">|</div> 4.current = 1 4.wrap = <div class="middle1">|</div> 5.current = 1 5.wrap = <div class="middle2">|</div> 6.wrap = <div class="last">|</div> 6.current = 1 7.current = 1 } }
Samples:
Content Element which shows also single elements
Official documentation:


Comments (0)