Copied to clipboard

Flag this post as spam?

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


  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Mar 04, 2013 @ 12:33
    Warren Buckley
    0

    URL Picker uComponents DataType - Recusive Value

    Hello all,
    I am trying to use the uComponents DataType UrlPicker which stores a URL, open in new window and the title.
    Which works fantasitcally well with Razor.
    The problem I am currently having is when I want to get a recursive value of this. However the datatype is still storing values even if the urlPicker data type is empty.

    //URL picker data type (Fetch it recursively)
    var brandLinkNew = Model._brandLinkNew;
    
    if (brandLinkNew != null)
    {
       brandLinkNew.Title;
    }

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Mar 04, 2013 @ 12:51
    Jeroen Breuer
    1

    I don't think there is really a good solution for this. I think the url picker always stores a value so it will never recursively go to the parent. It might be best to check if an url is available and if it's not go to the parent and fetch the property from there.

    Jeroen

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Mar 04, 2013 @ 12:58
    Warren Buckley
    0

    Jeroen, how would I go about doing the alternative way you have suggested?

    Cheers,
    Warren :) 

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Mar 04, 2013 @ 13:04
    Warren Buckley
    0

    Ok figured it out in the end with a while loop

        //URL picker data type
        var brandLinkNew = Model.BrandLinkNew;    
    
        while (brandLinkNew.Url == string.Empty)
        {        
            brandLinkNew = Model.Parent.brandLinkNew;
        }
  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Mar 04, 2013 @ 13:23
    Warren Buckley
    1

    OK not quite the code I needed but this should do it now

        //URL picker data type
        var brandLink = Model.BrandLink;
    
        var current = Model;
        while (string.IsNullOrWhiteSpace(brandLink.Url) && Model.Parent.Id != -1)
        {
            brandLink = current.brandLink;
            current = current.Parent;
        }    
  • SM 19 posts 41 karma points
    Jul 30, 2013 @ 10:08
    SM
    0

    Try using LINQ

    var recursiveLink = Model.Content.AncestorsOrSelf()
    .Where(x => x.HasProperty("brandLinkNew") && !String.IsNullOrEmpty(UrlPickerState.Deserialize(x.GetPropertyValue("brandLinkNew").ToString()).Url))
    .Select(x => x.GetPropertyValue("brandLinkNew"))
    .Last();

    UrlPickerState brandLink= UrlPickerState.Deserialize(recursiveLink.ToString());

    Hope it will help you!

Please Sign in or register to post replies

Write your reply to:

Draft