Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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
Hi James,
What if you are trying something like this:
@(Umbraco.Truncate(item.GetPropertyValue("blogPostContent"),200,false));
@(Umbraco.Truncate(item.GetPropertyValue("
blogPostContent"),200,false));
Hope this helps,
/Dennis
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)
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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
Hi James,
What if you are trying something like this:
Hope this helps,
/Dennis
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)
is working on a reply...