Sharing multi tree node picker value across partials
Hi,
I have a staff listing section on my site for all members of the organisation. Each staff member can be assigned to an office based on selection through a multi tree node picker property.
For example, person A works at Office A, Person B also works at Office A. Person C works at Office B and so on.
I then have a landing page for each office and would like to dynamically loop through the staff listing and find the people who work at that office.
E.g. on Office A landing page, I would see 2 people based on my example above.
<h3>Meet our people</h3>
var OfficeId = Model.Id;
<p>@OfficeId</p>
@* loop through people and find any that have united kingdom as office *@
@{
var selection = Umbraco.Content(Guid.Parse("9d4127b2-fbbf-4e38-b38e-a09adcf3657c"))
.ChildrenOfType("staffMember")
.Where(x => x.IsVisible())
.OrderBy(x => x.Name);
}
<ul>
@foreach (var item in selection)
{
<li>
<a href="@item.Url()">@item.Name()</a>
@item.Value("Position")
@item.Value("EmailAddress")
@item.Value("ContactNumber")
@{
var office = item.Value<IEnumerable<IPublishedContent>>("office");
foreach (var o in office)
{
<p>Office: @o.Name</p>
<p>Office ID: @o.Id</p>
<a href="@o.Parent.UrlSegment/@o.UrlSegment">View @o.Name office</a>
<p>Region: @o.Parent.Name</p>
<a href="@o.Parent.UrlSegment">@o.Parent.Name</a>
<hr>
}
}
</li>
}
So far I have this, I can loop through all people and get their office - but I need to somehow only get staff that match the current office Id i'm viewing. In this case: Id 1131.
Maybe you can add a match condition to the where in the selection variable to only get the staffMembers that have the right office selected? Something like:
Not sure if you have to use the key in this case or if y.Id == OfficeId would work as well.
Edit: caution that in the code line above x.Value<IEnumerable<IPublishedContent>>("office") might come back as null and will throw you an error on the Any(). Might be better to add a null-check.
Sharing multi tree node picker value across partials
Hi,
I have a staff listing section on my site for all members of the organisation. Each staff member can be assigned to an office based on selection through a multi tree node picker property.
For example, person A works at Office A, Person B also works at Office A. Person C works at Office B and so on.
I then have a landing page for each office and would like to dynamically loop through the staff listing and find the people who work at that office.
E.g. on Office A landing page, I would see 2 people based on my example above.
What would be the best way to approach this?
Many thanks
So far I have this, I can loop through all people and get their office - but I need to somehow only get staff that match the current office Id i'm viewing. In this case: Id 1131.
Anyone?
Maybe you can add a match condition to the where in the selection variable to only get the staffMembers that have the right office selected? Something like:
Not sure if you have to use the key in this case or if
y.Id == OfficeId
would work as well.Edit: caution that in the code line above
x.Value<IEnumerable<IPublishedContent>>("office")
might come back as null and will throw you an error on theAny()
. Might be better to add a null-check.Thanks! I've been able to work with something similar and that's working. Thanks for your help.
Many thanks
is working on a reply...