Foreach Loop, then a content pickers page content? (7.4.3)
I have a for each loop that pulls each recipient. Each recipient has a content picker that selects a elf (separate doc type and page). From the sponsor I want to select two fields, first name and last name
Here's my code, I can't seem to get this one working.
@foreach (var item in CurrentPage.Recipient.Where("UmbracoNaviHide == false"))
{ <td>
@item.Id
</td>
<td>
@if(item.HasValue("elf")){
var elfContent = item.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("elf");
var elfBtn = Umbraco.TypedContent(item.GetPropertyValue<int>("elf"));
foreach (var subItem in elfContent){
<a href="@elfBtn.Url">
@subItem.firstName @subItem.lastName
</a>
}
}
else{
<span>-</span>
}
</td>
}
Thanks for the response Alex. But it didn't seem to work. It actually decided to break the loop. This is before I even get to the content picker in the loop.
If I leave it with (below):
@foreach (var item in CurrentPage.Recipient.Where("UmbracoNaviHide == false"))
Yes the current page would "RecipientList" which only allows the doctype 'recipient' to be displayed on the list. If there's a way I can screenshare with you that could work.
Foreach Loop, then a content pickers page content? (7.4.3)
I have a for each loop that pulls each recipient. Each recipient has a content picker that selects a elf (separate doc type and page). From the sponsor I want to select two fields, first name and last name
Here's my code, I can't seem to get this one working.
Hi Rylan
This code works only with Property Value Converters enabled, do you have it? Property Value Converters are part of the core only since 7.6 version.
Thanks,
Alex
I'm not using 7.6 properties im running 7.4
I tried using multiple ways to make this work including 7.6 code and couldn't figure it out.
anyone?
Also tried this:
Hi Rylan
Try this code:
Do not mix dynamics with strongly typed models.
Thanks,
Alex
Thanks for the response Alex. But it didn't seem to work. It actually decided to break the loop. This is before I even get to the content picker in the loop.
If I leave it with (below):
I get this error:
Rylan, this code " @foreach (var item in CurrentPage.Recipient.Where("UmbracoNaviHide == false"))" and code that gives an error, can't work
Please use strongly typed objects.
CurrentPage is a dynamic object, try to avoid it.
Thanks,
Alex
This code isn't working because of this line:
Rylan, try this loop instead:
@foreach (var item in Umbraco.AssignedContentItem.GetPropertyValue
Thanks,
Alex
It works fine normally when I don't try to pull specific fields from the content pickers page.
Normally the .Url .Name will work just fine.
I added
and get this error
Hi Rylan
Did you solve the issue?
Thanks,
Alex
Not yet Alex, that didn't make it work lol thats what error I get above.
This code is working for me:
Thanks Alex, I tried that code outside of my current loop and it still isn't working. I get a "Value cannot be null."
Do you think I'm not calling the right Models?
at the top of the page I have:
What line causes the problem?
Maybe problem with this line - Umbraco.AssignedContentItem.GetPropertyValue<>
What type of property is "recipient"?
Thanks,
Alex
Yes, it is a problem with that line.
Recipient is a document type.
Thanks for all the help so far, hoping to get this workign soon Lol.
Where are "Recipient" documents placed?
Are they under the current page?
Yes the current page would "RecipientList" which only allows the doctype 'recipient' to be displayed on the list. If there's a way I can screenshare with you that could work.
Then iterate over child nodes like here:
Getting closer I think.
New variant of code:
Holy crap! You did it!
Yay!
Thanks Alex for all the help :)
Rylan, You are welcome!!!!
Really help to achieve it.
Alex
is working on a reply...