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 5058 posts 15520 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 5058 posts 15520 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))

Please Sign in or register to post replies

Write your reply to:

Draft