Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm currently stuck on getting the URL for a content picker in a macro.
The selected content gets passed this way:
Unfortunately, all posts about how to translate this to an URL or IPublishedContent seem to use old APIs like ToPublishedContent() or seem to be hacky or require injecting services and multiple calls to them.
I got as far as getting an IContent object from the umb-URL:
var target = Udi.Parse(Model.MacroParameters["target"] as string) as Umbraco.Core.GuidUdi;
var targetNode = Services.ContentService.GetById(target.Guid);
What is the official way to translate the UDI to an URL inside a macro? Pretty sure there has to be an easy and intuitive way.
I'm making the assumption you are in a Macro Partial View?
You are pretty close to be honest, except you shouldn't be using the Content Service.
In a Macro Partial View you have access to the Umbraco helper class which is prefect for getting IPublishedContent out.
So, what I would do is:
var target = Udi.Parse(Model.MacroParameter["target"] as string);
var contentNode = Umbraco.Content(target);
This will give you contentNode as an IPublishedContent allowing you to then call target.Url() (Note: If you just access the .Url property and not the .Url() extension method, if you are on a newer version of Umbraco you will get an obsolete warning on it).
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted