Try our conversational search powered by Generative AI!

Iterating through ContentArea items


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;
@Html.PropertyFor(x => questPage)

Mar 10, 2014 14:28


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? 

Mar 10, 2014 15:36

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 


Mar 10, 2014 15:39

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.

Mar 11, 2014 11:37
gabed123 - Jul 02, 2019 18:25
Does this require a certain directive or assembly reference?

if (CurrentPage.MainContentArea.Items.Any()) { foreach (var c in CurrentPage.MainContentArea.Items) { Response.Write("ContentArea Items" + c.GetContent().Name); } }
Edited, Apr 08, 2014 11:56

Valdis Iljuconoks Thank you, that's exactly what I was looking for.

Aug 22, 2014 15:54
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.