Umbraco 7. Multinode tree picker skip nodes that no longer exist
In Umbraco 7, we have a Mulitnode tree picker on a node. We choose a different node with the MNTP. We then delete the picked node out of the Umbraco tree, but NOT out of the MNTP on the original node. In C# how would we loop through the MNTP and check to see if the chosen node in the MNTP exists anymore?
Presuming you are getting the IPublishedContent for each picked item, you can filter out any nulls returned by Umbraco.TypedContent:
eg
If your Multinode Tree Picker is called 'RelatedContent' and you are storing picked items as CSV:
if (Model.Content.HasProperty("RelatedContent") && Model.Content.HasValue("RelatedContent"))
{
// get selected ids
var nodeIds = Model.Content.GetPropertyValue<string>("RelatedContent").Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)
.Select(int.Parse);
// turn ids into IPublishedContent, filter out nulls
var relatedContentNodes = Umbraco.TypedContent(nodeIds).Where(x => x != null);
}
Umbraco 7. Multinode tree picker skip nodes that no longer exist
In Umbraco 7, we have a Mulitnode tree picker on a node. We choose a different node with the MNTP. We then delete the picked node out of the Umbraco tree, but NOT out of the MNTP on the original node. In C# how would we loop through the MNTP and check to see if the chosen node in the MNTP exists anymore?
Hi Carlos
Presuming you are getting the IPublishedContent for each picked item, you can filter out any nulls returned by Umbraco.TypedContent:
eg
If your Multinode Tree Picker is called 'RelatedContent' and you are storing picked items as CSV:
If you install this package this will be handled for you : https://our.umbraco.org/projects/developer-tools/umbraco-core-property-value-converters/
You will then do this in your code :
This will return a list of only publish items from your picker
Dave
is working on a reply...