-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with getting value from a Macro partial #90
Comments
Hi @MMasey I've actually never tried using it in a macro, but having a look at the Core source, it does look like property value converters are not getting called (which kinda makes sense since it isn't a property). I guess one way to do it, is to create an extension method that does the conversion using System.Collections.Generic;
using System.Linq;
using System.Web;
using RJP.MultiUrlPicker.Models;
using Umbraco.Web.Models;
namespace WebApplication
{
public static class PartialViewMacroModelExtensions
{
public static IEnumerable<Link> GetLinks(this PartialViewMacroModel model, string alias)
{
var value = model.GetParameterValue<string>(alias);
if(value == null)
{
return Enumerable.Empty<Link>();
}
return new MultiUrls(HttpUtility.HtmlDecode(value));
}
public static Link GetLink(this PartialViewMacroModel model, string alias)
{
return GetLinks(model, alias).FirstOrDefault();
}
}
} and then you can use it in your macro partial @foreach(var link in Model.GetLinks("test"))
{
<a href="@link.Url">@link.Name</a>
}
|
It works like a charm, thank you so much 😄 I have a question regarding the MultiUrls class. In your source it says that it is obsolete and you should used Also, if this is going into core, this information would be useful in the docs (I know it's a very small use case, but you never know) |
Happy to hear that it works 🙂 The plan was to remove the I noticed that it was marked as a macro parameter editor in Core too and after talking to @nul800sebastiaan I created a PR to remove it since it's not supported because macro parameters don't use the value converters. |
Nice one, thanks for the update 👍 |
Does that mean they will remove the macro parameter editor for new releases of Umbraco? btw, thanks for the comment, since I was getting the same issue. |
Heyo,
I'm currently have some issues with getting the
IEnumerable<Link>
value whilst inside a Macro Partial. I think it's because in order to retrieve a value from a Macro, you need to useModel.GetParameterValue<IEnumerable<Link>>("links");
(for example) which i'm guessing means it doesn't use the standard property value converters.I'm able to get the value as a string, but i'm not sure what the best way is to convert that into the
IEnumerable<Link>
value i need.Do you have any suggestions?
Thanks
P.S. super excited to see that this is going into core, H5YR!
The text was updated successfully, but these errors were encountered: