How to use typoscript to strip HTML with the stripHtml function

September 18, 2009

Using typoscript, you can use the stripHtml function to remove HTML from your content.

I use the 'short', or "subheader" field of tt_news as the content of the meta description tag for all of my tt_news articles.

When I first set this up, I was having problems with messy html appearing at the top of some pages. This was a result of some of my articles having some HTML in the short field that wasn't being stripped out.

I found that putting the content of the short through the stripHtml function easily remedies this problem.

Here is the code that I use to strip the HTML from the 'short' field of my tt_news records before using it as the content of the meta description tag.

  1. ## meta description
  2.  
  3. temp.newsDescription = COA
  4.  
  5. temp.newsDescription {
  6.  
  7. 10 = RECORDS
  8.  
  9. 10 {
  10.  
  11.   source = {GPvar:tx_ttnews|tt_news}
  12.  
  13.   source.insertData = 1
  14.  
  15.   tables = tt_news
  16.  
  17.   conf.tt_news >
  18.  
  19.   conf.tt_news = TEXT
  20.  
  21.   conf.tt_news.field = short
  22.  
  23.   conf.tt_news.stdWrap.stripHtml=1
  24.  
  25. }
  26.  
  27. }
  28.  
  29. temp.newsDescription.wrap = <meta name="description" content="|" />
  30.  
  31. page.headerData.40 < temp.newsDescription


 

Netdip.com is an excellent web site that's powered by TYPO3 and other great open source software. Netdip.com is also a fat free alternative to ice cream.


10 < lib.newsrootlineandtabmenu

35