As we've seen above stdWrap is a concept that operates - based on it's proerties - on a certain value. But there is another important task of stdWrap which may be even more popular (or necessary). That is to fetch external content, for instance the title of the page, the current date, a cObject, number of rows from a select-statement, a filelist from a directory or a global variable.
Actually stdWrap is a concept divided into three parts.
Get data
Override / Conditions
Parse data
The example above shows only the parsing facilities of stdWrap (3). We're now going to look at "Get data" (1) and "Override / Conditions" (2), which provides a way to make control structures in Typo3 (although a bit "backwards" and complex).
The primary property here is .field. This fetches the value of the field given by the property. The very good question is, "... value of a field from where, which record?".
The answer is "by default, the page record..." (here "page" refers to the current page, we're on) "... but 'inside of' CONTENT, RECORD and HMENU cObjects, it's the 'current record' we're dealing with in that particular case". You'll find notes about this by the object descriptions.
Technically all this is going on in the class tslib_cObj in tslib_content and the 'current record' is defined by cObj->data.
.current - what is that?
Often the "current value" is refered to. Some functions need to pass a single value to the "public" (that's us and stdWrap...) and therefore sets a "register" called "current", the value of which we can easily get by the stdWrap property ".current = 1" (boolean). Whenever the "current" register is used, there will be a notice in the TSref.
Example:
page.10 = TEXT
page.10.value = Hello world
page.10.field = title
(After this, the lines "page = PAGE" and "page.typeNum=0" is assumed)
The output becomes "Startpage" and not "Hello world". That is because the input value from the TEXT cObject is overridden by the value of the field "title", defined by the .field property of stdWrap. Wow!
If you would like to see, which fields are available and what their content is, try to add the property ".debugData=1"
This is what you get. If you examine the HTML-code, you'll see that this must truely be "debug-information" because it's sent off to the browser before any of the page content.
Now, try to hit the page a second time. It didn't appear again, because the page got cached after the first rendering! Wow. So because the facility only outputs information during execution of TypoScript (during the page being rendered), you must continually clear the cache (or set a no_cache-option) in order to see the output.
Example: Get another field
page.10 = TEXT
page.10.value = Hello world
page.10.field = crdate
This outputs a number, which is UNIX-time since 1970 (number of seconds since then).
Challenge (stdWrap/1)
Using the parsing-properties of stdWrap, are you able to format this date to a humanly readable output?
Example: .data
If you would like to get other values, the .data property is often more sufficient. You can even use that to get your fields like before. So
page.10 = TEXT
page.10.field = title
and
page.10 = TEXT
page.10.data = field:title
does the same in this case (exception is the TMENU object, where the ->)
Getting the value of a global var:
Before you continue here, please go to "index.php?id=5"
page.10 = TEXT
page.10.data = global:id
outputs "5"
page.10 = TEXT
page.10.data = global:HTTP_GET_VARS|id
outputs also "5" (but this is from HTTP_GET_VARS[id])
page.10 = TEXT
page.10.data = leveltitle:1
outputs "Content elements" (which is the title of the page on level 1 in the rootline - you're currently in the branch 'Startpage/Content elements/Insert content')
Challenge (stdWrap/2)
Can you make the .data property return the page-titel of the page one level before the current page ('parent page')?
stdWrap provides simple "control structures" by means of comparing properties. To mention some of them, they are named override, ifEmpty, required, if, fieldRequired.
page.10 = TEXT
page.10.value = Hello world
page.10.override = Hello heaven
outputs "Hello heaven" instead becuase if override returns something, the original value is substituted.
page.10 = TEXT
page.10.value = Hello world
page.10.override.field = subtitle
Better example, because now "Hello world" is substituted only if the Subtitle field of the current page record is not blank. In most cases this field is blank, but try "index.php?id=20"...
Challenge (stdWrap/3)
Could you turn it around - using another of the comparing properties - so that the default value is the subtitle, but in case it's empty, it's replaced with "Hello World"
Challenge (stdWrap/4)
With your results from challenge 3, could you wrap the whole thing in <h3>...</h3>-tags? And could you replace "Hello world" with the page-title instead, which - in case it's present - is wrapped in <font color="red"> ... </font>