Copied to clipboard

Flag this post as spam?

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


  • Levente Kosa 136 posts 352 karma points
    Apr 14, 2020 @ 12:20
    Levente Kosa
    0

    Get data through Multi Url Picker

    Hi,

    I'm looking for a solution to get a custom Value through Multi Url Picker in Umbraco 8. So where my url picker points, I would like to access that page data. I know I can access to Uid, but I can't figure the next step out. Like can I I get the Id from Udi maybe, so I can do Umbraco.Content(1337).Value("foo") somehow?

  • Yakov Lebski 591 posts 2346 karma points
    Apr 14, 2020 @ 12:40
    Yakov Lebski
    0

    at beginig

    @using Umbraco.Web.Models
    

    code

    var links = root.Value<IEnumerable<Link>>("links");
                                    if (links.Any())
                                    {
                                        <ul>
                                            @foreach (var link in links)
                                            {
                                                <li><a href="@link.Url" target="@link.Target">@link.Name</a></li>
                                            }
                                        </ul>
                                    }
    
  • Levente Kosa 136 posts 352 karma points
    Apr 14, 2020 @ 14:11
    Levente Kosa
    0

    Hi, thanks for the answer. I think I asked wrong. I already got this part. My question is that how can I access to other data as well. For example with this Url picker I point to a page, where I have a Title property.

    I know I can't do @link.Value("title"), but maybe there is another way.

  • Levente Kosa 136 posts 352 karma points
    Apr 14, 2020 @ 15:01
    Levente Kosa
    0

    The other way for me would be to extend the Url Picker with a custom field, but I don't know if it's possible and how. Specificaly I would like to add an aria-label to Url Picker.

  • Tim Miller 32 posts 252 karma points
    Apr 14, 2020 @ 18:07
    Tim Miller
    102

    The Link model has a Udi that you can use to get to the linked internal node. External links you will just have to live with the Name that has been entered in the editor. So I'm checking the type, then getting the internal node (the null check is there in case it has been unpublished or deleted). Then check to see if it has a value for the "title" property and use that as the link text.

    Try this:

    @foreach (var link in links)
    {
        string linkText = link.Name;
        if (link.Type == LinkType.Content)
        {
            var linkedNode = Umbraco.Content(link.Udi);
            if(linkedNode != null && linkedNode.HasValue("title"))
            {
                linkText = linkedNode.Value<string>("title");
            }
        }
        <li><a href="@link.Url" target="@link.Target">@linkText</a></li>
    }
    
  • Levente Kosa 136 posts 352 karma points
    Apr 14, 2020 @ 20:48
    Levente Kosa
    0

    Tim, this is just perfect. Thank you so much for your help!

Please Sign in or register to post replies

Write your reply to:

Draft