November 7, 2006

Formatting HTML in Typoscript Objects

By: Ron Hall

Cat: TYP03, TypoScript

One of the challenges that I faced early in my TYPO3 efforts was reading the HTML source code that was output from my Typoscript because it all came out on one line. There is, however, a way around this.

One of the challenges that I faced early in my TYPO3 efforts was reading the HTML source code that was output from my Typoscript.

Take for instance this code for a simple TMENU (opens in new window).

Which produces HTML like this (opens in new window).

Of course, this is very hard to read since all of the HTML comes out as one continuous line.

However, structure the Typoscript like this (opens in new window).

And you get HTML like this (opens in new window).

This HTML is much easier to read and therefore easier to debug. By using "()" instead of "=" to assign HTML values you will keep any tabs, spaces or line returns you put between the "()" thus allowing you to format your HTML source code.

 

Comments

When using subst_elementUid are you getting the page UID?
Michael Cannon, 01/10/07
 
Yes, it is the page UID. I use it for CSS styling so I can create non-javascript rollovers with background elements.

Of course, that is only practical for the first couple of levels of the site (which don't change much) since changes to the site structure dictate changes in the CSS and background images.
Ron Hall, 01/10/07
 

Post a Comment

Please note that it can take a minute or two to save your comment. Wait for the page to refresh to see your comment.