The HTML cObject
The HTML cObject, along with the TEXT, COA and USER cObjects is one of the workhorses of the cObject family. It can be used simply to ouput a static string, but is also very commonly used in conjunction with Typoscript's stdWrap function.
Example 1: Static Text
The HTML cObject has only one property–"value"–and that property has the data type HTML/stdWrap. This means that we can supply content to the cObject either in the form of a string or from stdWrap and then further transform the content using stdWrap. For our first example, we simply provide the value property with a text string:
- lib.tsref.cObject.HTML.1 = HTML
- lib.tsref.cObject.HTML.1{
- value = Hello world!
- }
This, unsurprisingly, results in the following output:
Example 2: Transforming Static Text
For our second example, we will still load the value property with a string of static text, but we'll also use the stdWrap function to transform the text by
- converting it to upper-case, and
- wrapping it in opening and closing <em> tags
- lib.tsref.cObject.HTML.1 = HTML
- lib.tsref.cObject.HTML.1{
- value = Hello world!
- value {
- case = upper
- wrap = <strong>|</strong>
- }
- }
The above code produces the following output (shown as HTML and as rendered by the browser):
Example 3: Supplying Content with stdWrap
The transformations shown above are not especially interesting with static text–after all, it's possible to simply type the text in uppercase (or better, use CSS), complete with HTML tags. But once we appreciate that Typoscript's stdWrap function can also supply content, the stdWrap transformations become much more interesting.
In our third and final example, we demonstrate one way to use stdWrap to supply and transform content with the HTML cObject:
- lib.tsref.cObject.HTML.3 = HTML
- lib.tsref.cObject.HTML.3{
- value {
- data = page:subtitle
- case = upper
- wrap = <strong>|</strong>
- }
- }
Add comment