Reputation: 17467
I'm trying to iterate through the muti node picker with razor. My alias for my widget is "venuesPicker." I'm getting the error, "cannot load macro file." Here's what I have so far:
<umbraco:Macro runat="server" language="cshtml">
@{
using uComponents.Core;
using uComponents.Core.uQueryExtensions;
foreach (var x in Model.venuesPicker)
{
@x.highlightTitle
}
}
</umbraco:Macro>
Upvotes: 2
Views: 6434
Reputation: 827
You can use uQuery.getNodesByCSV or uQuery.getMediaByCSV too. uQuery was added to Umbraco core in 4.9 I think, otherwise you can install uComponents package
so for example I have something like this in 4.9.1 to loop through some media
@using umbraco.MacroEngines
@using umbraco.cms.businesslogic.media
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
<div class="slideshow">
@foreach (Media img in uQuery.GetMediaByCsv(Model.lightBoxImages))
{
<figure>
<a href="#">
<img src="@img.GetImageUrl()" />
</a>
</figure>
}
</div>
}
Upvotes: 0
Reputation: 10942
Check out my answer to this our.umbraco.org forum post. Basically, depending on whether the MNTP is using XML or CSV, you can do one of the following:
CSV:
@using umbraco.MacroEngines
@inherits DynamicNodeContext
@if (Model.HasValue("venuesPicker"))
{
string[] ids = Model.venuesPicker.Split(',');
<ul>
@foreach (string id in ids)
{
var node = Library.NodeById(id);
if (node.Id != 0)
{
// If node exists:
<li><a href="@node.Url">@node.Name</a></li>
}
}
</ul>
}
XML:
@using umbraco.MacroEngines
@inherits DynamicNodeContext
@if (Model.HasValue("venuesPicker"))
{
<ul>
@foreach (var item in Model.venuesPicker)
{
var node = Library.NodeById(item.InnerText);
if (node.Id != 0)
{
// If node exists:
<li><a href="@node.Url">@node.Name</a></li>
}
}
</ul>
}
Upvotes: 7