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:

  1. lib.tsref.cObject.HTML.1 = HTML
  2. lib.tsref.cObject.HTML.1{
  3.   value = Hello world!
  4. }

This, unsurprisingly, results in the following output:

TS output
Hello world!

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

  1. converting it to upper-case, and
  2. wrapping it in opening and closing <em> tags
  1. lib.tsref.cObject.HTML.1 = HTML
  2. lib.tsref.cObject.HTML.1{
  3.   value = Hello world!
  4.   value {
  5.     case = upper
  6.     wrap = <strong>|</strong>
  7.   }
  8. }

The above code produces the following output (shown as HTML and as rendered by the browser):

HTML output
<strong>HELLO WORLD!</strong>
TS output
HELLO WORLD!

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:

  1. lib.tsref.cObject.HTML.3 = HTML
  2. lib.tsref.cObject.HTML.3{
  3.   value {
  4.     data = page:subtitle
  5.     case = upper
  6.     wrap = <strong>|</strong>
  7.   }
  8. }
HTML output
<strong>TYPOSCRIPT'S HTML COBJECT</strong>
TS output
TYPOSCRIPT'S HTML COBJECT

Comments

No comments

Add comment

*
*
* required field

HTML cObject in the TSref

www.typo3apprentice.com
A Bedlam Hotel project © 2007—2010

Report a problem with this page

Bookmark and Share