Aximili
Aximili

Reputation: 29444

Umbraco 7: How to get child nodes in a Layout (.cshtml)

This is what I am doing

enter image description here

This is the code circled red (where it throws an error):

@foreach (var slide in Model.Children)

I thought you used to be able to do something like that in Umbraco 4.7.

How do you loop through the child nodes correctly in Umbraco 7?

Upvotes: 2

Views: 5273

Answers (1)

Morten OC
Morten OC

Reputation: 1784

You have access to CurrentPage which is a dynamic Umbraco model.

So like

@foreach (var slide in CurrentPage.Children)
{
    <p>@slide.Name</p>
}

On side node: Instead of using Umbraco.Field("pageName"), Use CurrentPage.PageName.

Upvotes: 5

Related Questions