Copied to clipboard

Flag this post as spam?

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


  • James 251 posts 1169 karma points
    Jul 29, 2014 @ 09:24
    James
    0

    Umbraco.Truncate

    I am using some code for paging on a portfolio page that calls all my portfolio items.

     

    Currently I have to use the followign code to display sections of portfolio items:

     

    @item.GetPropertyValue("PortfolioItemTitle")

     

    Is there a way for me to truncate this? I could do with the first 100 characters of a portfolio item.

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Jul 29, 2014 @ 09:41
    Sebastiaan Janssen
    100

    Why do you ask, the answer is in the title? ;-)

    @(Umbraco.Truncate(item.GetPropertyValue("PortfolioItemTitle"), 100, false).ToString());
    

    Not sure if ToString() is necessary.

  • James 251 posts 1169 karma points
    Jul 29, 2014 @ 14:23
    James
    0

    @(Umbraco.Truncate(item.GetPropertyValue("PortfolioItemBodyText").ToString(), 100, false))

     

    This worked for me :)

     

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Jul 29, 2014 @ 14:26
    Sebastiaan Janssen
    0

    Not that if you have HTML in the title you will want to strip that as well:

    @(Umbraco.Truncate(Umbraco.StripHtml(item.GetPropertyValue("PortfolioItemBodyText").ToString()), 100, false))

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies