How to use typoscript to strip HTML with the stripHtml function
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.
## meta description
temp.newsDescription = COA
temp.newsDescription {
10 = RECORDS
10 {
source = {GPvar:tx_ttnews|tt_news}
source.insertData = 1
tables = tt_news
conf.tt_news >
conf.tt_news = TEXT
conf.tt_news.field = short
conf.tt_news.stdWrap.stripHtml=1
}
}
temp.newsDescription.wrap = <meta name="description" content="|" />
page.headerData.40 < temp.newsDescription