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!
I'm having trouble accessing child nodes inside a foreach. I'll start by providing the content structure:
root
blog
blogpost1
block1
block2
...
blogpost2
I'm on the blog page and I want to display, for each blogpost, the title (property of blogpost) and the property text of the first block.
Right now I have this, and it works:
<umbraco:Macro runat="server" language="cshtml"> @foreach (var item in @Model.BlogPost.Where("Visible")) { @item.blogPostTitle; } </umbraco:Macro>
But when I try to go further down the tree, like so:
<umbraco:Macro runat="server" language="cshtml"> @foreach (var item in @Model.BlogPost.Where("Visible")) { @item.blogPostTitle;
@item.Down(2).text } </umbraco:Macro>
I always get the Error loading MacroEngine script (file: )
I probably can't do the @item.Down(2).text and I don't know how to do it properly.
Can anyone shed some light ?
Thanks
Hi Joao,
I think you just need to go Down(1) to get to block1 as Down(2) would take you to the child of block1 which doesn't exist?
Thanks,
Jeavon
Sorry, should be Down(0) which is to traverse one level
Did you get this working ?
Yep, it worked with .Down(0)
Thank you!
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
DynamicNodeWalker Problems
Hello!
I'm having trouble accessing child nodes inside a foreach. I'll start by providing the content structure:
root
blog
blogpost1
block1
block2
...
blogpost2
block1
block2
...
...
I'm on the blog page and I want to display, for each blogpost, the title (property of blogpost) and the property text of the first block.
Right now I have this, and it works:
<umbraco:Macro runat="server" language="cshtml">
@foreach (var item in @Model.BlogPost.Where("Visible"))
{
@item.blogPostTitle;
}
</umbraco:Macro>
But when I try to go further down the tree, like so:
<umbraco:Macro runat="server" language="cshtml">
@foreach (var item in @Model.BlogPost.Where("Visible"))
{
@item.blogPostTitle;
@item.Down(2).text
}
</umbraco:Macro>
I always get the Error loading MacroEngine script (file: )
I probably can't do the @item.Down(2).text and I don't know how to do it properly.
Can anyone shed some light ?
Thanks
Hi Joao,
I think you just need to go Down(1) to get to block1 as Down(2) would take you to the child of block1 which doesn't exist?
Thanks,
Jeavon
Sorry, should be Down(0) which is to traverse one level
Hi Joao,
Did you get this working ?
Yep, it worked with .Down(0)
Thank you!
is working on a reply...