Copied to clipboard

Flag this post as spam?

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


  • Jimmy Dan Mortensen 77 posts 197 karma points
    Oct 29, 2015 @ 13:35
    Jimmy Dan Mortensen
    0

    Calling a multiurlpicker from a contentpicker

    Hi folks,

    Probaply a total newbie question here, but I am trying to create a list of links that I can re-use on different pages. I wanna create a list of active campaigns. I have created a uComponents MultiUrlPicker, and saved it in a container on my root.

    On my page I have a content picker which points to the MultiUrlPicker. How do i do a foreach loop that shows all the links in the multiurlpicker?

    Here is what I have so far - but I don't think I am even close to the solution.

        var kampagneLink = Model.Content.GetPropertyValue("kampangeLinks"); //Returns id of container
    
        <ul>
        @if (kampagneLinks != null) {
        foreach (var link in Model.Content.GetPropertyValue<MultiUrlPickerState>("kampagneLinks").items)
        {
        if (!link.Validates())
        {
        continue;
        }
        <li><a href="@link.Url" target="@(link.NewWindow ? "_blank" : "_self")">@link.Title</a></li>
    }}</ul>
    

    I hope someone can guide me in the right direction.

    Best regards Jimmy Dan Mortensen

  • Mark Bowser 273 posts 860 karma points c-trib
    Oct 29, 2015 @ 13:53
    Mark Bowser
    0

    I think what you were missing is that Model.Content is the current page. After you grab the kampagneLinkContainer (shown in the first couple of lines below) you need to get the MultiUrlPickerState data off of the kampagneLinkContainer node instead of off of the current page.

    var kampagneLinkId = Model.Content.GetPropertyValue("kampangeLinks");         //Returns id of container
    var kampagneLinkContainer = Umbraco.TypedContent(kampagneLinkId);
    
    <ul>
    @if (kampagneLinkContainer != null) {
        foreach (var link in kampagneLinkContainer.GetPropertyValue<MultiUrlPickerState>("kampagneLinks").items)
        {
            if (!link.Validates())
            {
                continue;
            }
            <li><a href="@link.Url" target="@(link.NewWindow ? "_blank" : "_self")">@link.Title</a></li>
        }
    }
    </ul>
    

    Let me know how that works.

  • Jimmy Dan Mortensen 77 posts 197 karma points
    Oct 29, 2015 @ 14:08
    Jimmy Dan Mortensen
    0

    Hi Mark,

    Thank you for your quick reply :-) Unfortunately it is not working. It tells me that

    CS1061: 'uComponents.DataTypes.MultiUrlPicker.Dto.MultiUrlPickerState' does not contain a definition for 'items'

    Is it not possible to simply use the first variable (kampagneLinkId) in the foreach sentence? This variable returns the id of the muliturlpicker - shouldn't I be able to do something like this:

    foreach (var link in 8888.items)
    

    where 8888 beeing the ID of the multiUrlPicker in content

Please Sign in or register to post replies

Write your reply to:

Draft