Opticon Stockholm is on Tuesday September 10th, hope to see you there!
AI OnAI Off
Opticon Stockholm is on Tuesday September 10th, hope to see you there!
Hi!
The PropertyFor method is a way to render a single property but a Content Area contains a list of links to content items. What are you trying to achieve? Do you want to create links for each item in the Content Area?
I want to render each block in my Content area ( I limit by content area to a specific type)
Since the contentArea is blocks only I should be able to use PropertyFor
Try following code:
@{
var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
if (page != null && page.ContentArea != null && page.ContentArea.Items.Any())
{
foreach (var contentItem in page.ContentArea.Items)
{
var item = contentLoader.Get<YOUR_CONTENT_TYPE>(contentItem.ContentLink);
// output necessary properties from content instance
}
}
}
In each iteration variable `item` should point to concrete content type instance in your ContentArea.
if (CurrentPage.MainContentArea.Items.Any())
{
foreach (var c in CurrentPage.MainContentArea.Items)
{
Response.Write("ContentArea Items" + c.GetContent().Name);
}
}
I wanted to iterator (foreach) through the items of a content area and do a Html.propertyFor() on each of them.
Below example is from a link-list
@foreach (PageData questionPage in Model.Links.ToPages())
{
var questPage = questionPage;
<li>
@Html.PropertyFor(x => questPage)
</li>
}