New Snippet - Truncate your string with Razor helpers
Here's what i have done - using a helper to trim my string.
Here's the code:
@helper Truncate(string input, int length) { if (input.Length <= length) { @input } else { @input.Substring(0, length)<text>...</text> } }
@foreach(dynamic article in Model.Children) { @article.siteTitle var bodyText = article.siteContent.ToString(); @Truncate(bodyText, 20); @* ## YOU CAN COMBINE THIS WITH A MAC-PARAM..*@ }
New Snippet - Truncate your string with Razor helpers
Here's what i have done - using a helper to trim my string.
Here's the code:
Have fun dudes :)
If you add Html.Raw, then it also works when your string contains HTML tags. Bumped into this once... :)
is working on a reply...