This method is used to take a string (or a block of HTML) and truncate it to a specific length. It will optionally add an elipsis on the end for you (… ) and it is HTML Tag aware.
There are a number of overloads, but the most basic use case is this:
@Library.Truncate(Model.rteContent,100)
This will return the content of rteContent, but only the first 100 characters. Characters that are tags (e.g. <strong>) will not be counted towards the 100, and a … will be added on the end. If the truncation occurs in the middle of a tag, (e.g. there'd be no </strong>) the tag will still be closed.
first 300 letters + test, 2 questions
Hello guys,
I just upgraded my umbraco to 4.7.1 and would like to use razor. I have two problems:
- I would like to display first l300 letters of a description property of my document type using Razor.
- in some of the document the description is empty, how to run a quick test and display it only when exists?
thanks in advance,
Pawel
@Library.Truncate
This method is used to take a string (or a block of HTML) and truncate it to a specific length.
It will optionally add an elipsis on the end for you (… ) and it is HTML Tag aware.
There are a number of overloads, but the most basic use case is this:
@Library.Truncate(Model.rteContent,100)
This will return the content of rteContent, but only the first 100 characters. Characters that are tags (e.g. <strong>) will not be counted towards the 100, and a … will be added on the end.
If the truncation occurs in the middle of a tag, (e.g. there'd be no </strong>) the tag will still be closed.
found on http://umbraco.com/follow-us/blog-archive/2011/9/22/umbraco-razor-feature-walkthrough%E2%80%93part-8.aspx
Thanks a lot Bas, starts to taking some shape :)
is working on a reply...