PreviewText

Vote:
 
Hellooo! I've noticed there's a builtin property in PageTemplateContainer called PreviewText. This property is used to either return the CurrentPage["MainIntro"] or CurrentPage["MainBody"]. If the last one, it's suppose to truncate it to the first 400 characters. But the string returned is not even near 400 characters. Is 400 including the HTML tags, perhaps? I'm also trying to use this TextIndexer.StripHtml function directly to truncate a property I've defined in a template, but I'm getting some weird results... Example: The following text is stored in the property "Ingress" (propertylongstring):

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam leo. Nullam lorem. Nam et magna. Pellentesque cursus, mi in porta sodales, risus lorem elementum leo, ac venenatis ligula lorem in quam. Maecenas consequat magna in massa ornare adipiscing. Proin in libero. Cras leo tellus, commodo nec, rhoncus ac, viverra sed, lorem. Nulla felis velit, sagittis eu, tincidunt et, tempus eget, diam. Curabitur lectus. Aliquam lorem est, dictum vehicula, tristique eu, convallis nec, quam. Suspendisse a velit. Sed consequat. Aliquam nec libero vel arcu tincidunt imperdiet. Etiam interdum felis. Quisque dignissim feugiat quam. Sed scelerisque risus at tellus. Proin vel dolor. Sed iaculis adipiscing odio. Donec dignissim lacus.

Integer rhoncus. Pellentesque egestas, pede eget sagittis rhoncus, turpis arcu tincidunt pede, non mattis est nunc in diam. Donec sed leo sed lacus dapibus venenatis. In varius bibendum lacus. Pellentesque commodo. Morbi eget quam at felis varius adipiscing. Nam lacus. Curabitur ornare wisi quis nunc. Ut ut massa. Aliquam a orci sit amet nunc interdum mattis.

After executing the following line strReturnValue = TextIndexer.StripHtml(page["Ingress"].ToString(), 400); I get this result back: Lorem ipsum dolor sit amet... Integer rhoncus. Pellentesque egestas, pede eget sagittis rhoncus, turpis... What's wrong here? Thanks, Frank :)
#12101
Jun 29, 2004 22:21
Vote:
 
StripHtml was probably not a good method name for this one as it does much more than strip away html, it was built for search results and have a algorithm that tries to extract the beginning of some sentences. The length property will control how much html that is being processed rather than the actual text being returned to you. Another html strip method (see CreatePreviewText) is used by the subscription mailer, a sample can be found at: http://www.episerver.com/templates/CommunitySample____4946.aspx
#13650
Jun 30, 2004 8:23
Vote:
 
I've never used the TextIndexer.StripHtml instead I've made my own stipper. using System.Text.RegularExpressions; public string StripHTML(string text, int maxlen) { string output; output = Regex.Replace(text, "<[^>]*>", " "); if (output.Length > maxlen) return output.Substring(0, maxlen) + "..."; else return output; }
#13651
Jun 30, 2004 8:27
Vote:
 
Thanks! Just what I was looking for. Frank :)
#13652
Jun 30, 2004 10:36
Vote:
 
As Per mentioned, the PreviewText does not work the way it is described in the SDK. This has been corrected in the next version of the SDK. The correct description below: PageTemplateContainer.PreviewText: The preview text is determined by the following: If the page has a MainIntro property, this string is used to create the preview text, otherwise the MainBody property is used, if it exists. The first 400 characters of the text is extracted and cleaned from any html. Finally, the remaining text is split into truncated sentences using the format "First truncated sentence... Second truncated sentence... etc". If the page has neither a MainIntro nor a MainBody property, an empty string is returned.
#13653
Jun 30, 2004 10:48
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.