Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mike Manusama 45 posts 195 karma points
    Dec 12, 2017 @ 18:31
    Mike Manusama
    0

    Grab a URL from content picker

    This is probably something so easy, which is why I can't manage to find it in the forum anywhere. I am using the content picker for a button on my macro and the end goal is for the user to just pick the page in the document tree and have the href tag link to that Url. I've tried a slew of things and have not gotten anywhere.

    Here is my code:

    <div class="feature-left-content">
          <h3>@Model.MacroParameters["ServiceSpecialty"]</h3>
          <p>@Model.MacroParameters["ServiceContent"]</p>
          <a href='@Umbraco.NiceUrl(CurrentPage.ServiceUrl)' class="btn btn-lg btn-primary btn-circle btn-scroll mt20">LEARN MORE</a> 
    

    Any idea what the issue could be? 'ServiceUrl' is the alias for the parameter I have given the content picker.

  • Amir Khan 1282 posts 2739 karma points
    Dec 12, 2017 @ 21:01
    Amir Khan
    0

    Hi Mike!

    It will likely be something like below, CurrentPage refers to the context of the current page, not the macro's context.

    Are the other two parameters rendering properly?

    Learn More

    Hope this helps,

    Amir

  • Mike Manusama 45 posts 195 karma points
    Dec 12, 2017 @ 21:15
    Mike Manusama
    0

    Hi Amir, thanks for the reply! The proposed solution did not render either, in fact it actually is shown with an error. The way I had it didn't render an error but didn't link properly. As far as the other parameters, those are working fine

  • Amir Khan 1282 posts 2739 karma points
    Dec 12, 2017 @ 21:17
    Amir Khan
    0

    What's the error?

    And sorry, it might be Umbraco.Content() Umbraco.TypedContent(), not UmbracoNiceUrl()

  • Mike Manusama 45 posts 195 karma points
    Dec 12, 2017 @ 21:25
    Mike Manusama
    0
    'Umbraco.Web.UmbracoHelper.NiceUrl(int)' has some invalid arguments
    
  • Amir Khan 1282 posts 2739 karma points
    Dec 12, 2017 @ 21:43
    Amir Khan
    100

    Alright, if you're using the new content picker here's how you do it, reference here: https://our.umbraco.org/forum/templates-partial-views-and-macros/85768-new-content-picker-as-macro-parameter-v761

    See below, just tested this::

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using Umbraco.Core.Models
    @using Umbraco.Web
    @using Umbraco.Web.Extensions
    @{
          IPublishedContent linkedNode = Udi.Parse(Model.MacroParameters["ServiceUrl"].ToString()).ToPublishedContent();
    }
    <a href="@linkedNode.Url">Link here</a>
    
  • Mike Manusama 45 posts 195 karma points
    Dec 12, 2017 @ 22:48
    Mike Manusama
    0

    Genius. Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft