Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • pawel 22 posts 42 karma points
    Mar 19, 2012 @ 23:48
    pawel
    0

    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 

  • Bas 3 posts 24 karma points
    Mar 21, 2012 @ 09:16
    Bas
    1

    @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

     

     

  • pawel 22 posts 42 karma points
    Mar 21, 2012 @ 21:39
    pawel
    0

    Thanks a lot Bas, starts to taking some shape :)

Please Sign in or register to post replies

Write your reply to:

Draft