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
    Oct 14, 2014 @ 13:23
    James
    0

    Truncating

    Hello All,

    I am using the following code to create content:

    var home = Model.Content.AncestorsOrSelf("Home").First();

    var blogs= home.Descendants("Blog").First();

    var items = blogs.Descendants("BlogPost").Where(x => x.GetPropertyValue("blogPostCategory").Equals("Funny"));

     

     

    @foreach (var item in items.Skip((page - 1) * pageSize).Take(pageSize).OrderBy("CreateDate desc"))

    {

    @item.GetPropertyValue("blogPostContent")

    }

     

    This code works great and now I want to truncate some of the content I am feeding out.

     

    How can i truncate : @item.GetPropertyValue("blogPostContent") so that it displays only the first 200 characters?

     

    When i do:

    Umbraco.Truncate(@item.GetPropertyValue("blogPostContent"), 200)

     

    I get the error "some invalid arguements".

     

    Any ideas?

     

    Kind regards,

     

    J

     

     



  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Oct 14, 2014 @ 13:38
    Dennis Aaen
    0

    Hi James,

    What if you are trying something like this:

    @(Umbraco.Truncate(item.GetPropertyValue("blogPostContent"),200,false));

    Hope this helps,

    /Dennis

     

  • Marcio Goularte 356 posts 1248 karma points
    Oct 14, 2014 @ 13:42
    Marcio Goularte
    0

    This code works . I made a substring.

    @item.GetProperty("blogPostContent").Value.ToString().Substring(0, @item.GetProperty("blogPostContent").Value.ToString().Length < 200 ? @item.GetProperty("blogPostContent").Value.ToString().Length : 200)

  • 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