Reputation: 13610
I'm trying to create a partial view macro that list all items (blog entries). I can read its name, but not the entry field like it's content:
@foreach (var page in CurrentPage.Children.Where("Visible").OrderBy("CreateDate desc"))
{
<div class="article">
<div class="articletitle">@page.Name</div>
<div class="articlepreview">
@Umbraco.Truncate(@page.Field("pageContent"),100)
<a href="@page.Url">Read More..</a>
</div>
</div>
<hr/>
}
All pages are defined as a ContentPage
(document type) where I've added Page Content (pageContent), type: Richtext editor
as a Tab: Content
element.
Do I need to cast the page or something to Contentpage
?
What Im trying to do Is to give a 100 char long preview of the content on my main page so the users can read a short excerpt before clicking on the item.
Upvotes: 0
Views: 128
Reputation: 341
Technically they are Properties of a doctype, not Fields.
So I believe this is what you are looking for:
@page.GetProperty("pageContent").Value
And truncate...
@Library.Truncate(@page.GetProperty("pageContent").Value,100)
However in this context you should be able to simply use…
@page.pageContent
So...
@Library.Truncate(@page.pageContent,100)
…should work!
Upvotes: 1
Reputation: 1691
I think this will give you the text you are looking for (I think your problem was just that extra @):
@Umbraco.Truncate(page.Field("pageContent"),100)
If you are running on umbraco 7+, try this:
@Umbraco.Truncate(page.AsDynamic().pageContent, 100)
Hope this helps!
Upvotes: 0