Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Truncating Blog Title in Recent Posts Transformation View modes: 
User avatar
Member
Member
kelements - 5/27/2011 6:44:30 PM
   
Truncating Blog Title in Recent Posts Transformation
Is there a way to truncate or set the character string to show 10 characters only and also include "..." ate the end.

Example: If a blog post is called:
"Cheeseburgers are great with cheese"

The truncated version would be:
"Cheeseburg ..."

Here is the blog title code that I would like to apply this to...
<a href="<%# GetDocumentUrl() %>"><%# Eval("BlogPostTitle", true) %></a>

THANKS!!

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 5/30/2011 3:23:00 AM
   
RE:Truncating Blog Title in Recent Posts Transformation
Hello,

There is a method called "TextHelper.LimitLength" for that. As per documentation:

LimitLength(object textObj, int maxLength, string padString)

<%# LimitLength("Some example long text", 10 , "...") %>
• Limits text specified in the first parameter to the length specified in the second parameter. The last parameter is the trimming postfix, i.e. the string appended to the end of the shortened string. The trimming postfix is included in the maximal length, i.e. if the "..." postfix is used with maximal length of 100 characters, the returned string will have the first 97 characters of the original string, followed by three dots.

If you use macro expressions, you can use the following parameter:

|(limitlength)<chars> - Calls TextHelper.LimitLength making your value having some maximum length with ellipsis

For more information on the macro approach please check the following article. For more information on the mentioned methods please check the API reference.

You can also write a custom transformation method, which would do the trimming and replacing for you as described in our documentation.

Best regards,
Boris Pocatko