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 am using Umbraco 8.1.4 and I am having a little problem with Macro Parameters.
Basically I am trying to use a content picker in a macro parameter and then use the url of the page selected as a link to that page.
<a href="@Model.MacroParameters["linkTo"]" role="button">
The button renders fine but the URL doesn’t work. It just shows the UDI (umb://document/…….)
I have searched around and found various solutions for previous Umbraco versions but they don’t seem to work in v8.
Is someone able to point me in the right direction for v8? I can get content pickers to work properly in a normal template just not as macro parameter?
When you write out a content picker value normally in a template then a 'Property Value Converter' runs behind the scenes and turns the picked identifier into a representation of the thing that was picked.
But inside a Macro Partial, and with Macro Parameters this magic does not happen :-( so what you are seeing for linkTo is the identifier of the picked content item...
... but you can use this to get your item with the UmbracoHelper's Content method... eg try
var linkTo = Umbraco.Content(Model.MacroParameters["linkTo"]);
<a href="@linkTo.Url()" role="button">
Perfect thanks Marc. I was very close with some of the attempts but was just struggling with the .Url()
That code works a treat and makes complete sense. Thanks mate.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted