Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,45 @@
@inject UmbracoHelper Umbraco
@inject IPublishedValueFallback PublishedValueFallback
@inject IPublishedUrlProvider PublishedUrlProvider

@*
This snippet lists the items from a Multinode tree picker, using the pickers default settings.
Content Values stored as xml.

To get it working with any site's data structure, set the selection equal to the property which has the
multinode treepicker (so: replace "PropertyWithPicker" with the alias of your property).

But for classic version of a macro you use the parameter settings
*@

@{ var selection = Model.Content.Value<IEnumerable<IPublishedContent>>(PublishedValueFallback, "PropertyWithPicker").ToArray(); }
@{
//example 1: using document type properties for this macro
var contentMntpSelection = Model.Content.Value<IEnumerable<IPublishedContent>>(PublishedValueFallback, "PropertyWithPicker")?.ToArray();

//example 2: using classic macro parameter
var selection = Model.MacroParameters.FirstOrDefault(p => p.Key == "product").Value?.ToString().Split(',');

<ul>
@foreach (var id in selection)
if (contentMntpSelection != null && contentMntpSelection.Any())
{
<ul>
@foreach (var item in contentMntpSelection)
{
<li>
<a href="@item.Url(PublishedUrlProvider)">@item.Name</a>
</li>
}
</ul>
}
else if (selection != null && selection.Any())
{
var item = Umbraco.Content(id);
<li>
<a href="@item.Url(PublishedUrlProvider)">@item.Name</a>
</li>
<ul>
@foreach (var id in selection)
{
var item = Umbraco.Content(id);
<li>
<a href="@item.Url(PublishedUrlProvider)">@item.Name</a>
</li>
}
</ul>
}
</ul>
}