Copied to clipboard

Flag this post as spam?

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


  • Anthony Candaele 1197 posts 2049 karma points
    Dec 11, 2013 @ 14:07
    Anthony Candaele
    0

    checking if uComponents Url Pickter is empty

    Hi,

    I'm having a problem checking if a Url Picker property is empty or not:

    @if (Model.Content.HasValue("announcementLink"))
        {   
            <h3>Link</h3>        
            if (CurrentPage.announcementLink.XPath("//link-title").InnerText != "")
            {                     
                    <i class="icon-link"></i> <a href="@CurrentPage.announcementLink.url" title="@CurrentPage.announcementLink.XPath("link-title").InnerText" target="_blank">
                        @CurrentPage.announcementLink.XPath("//link-title").InnerText
                    </a>    
             }
             else
             {                     
                    <i class="icon-link"></i> <a href="@CurrentPage.announcementLink.url" title="@CurrentPage.announcementLink.url" target="_blank">
                        @CurrentPage.announcementLink.url
                    </a>
             }
    

    Although my link property is empty is still passes this condition:

    @if (Model.Content.HasValue("announcementLink"))
    

    Does anyone have an idea how to solve this?

    Thanks for your help,

    Anthony

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 11, 2013 @ 20:09
    Jeavon Leopold
    101

    Hey Anthony,

    Are you using Umbraco v6 and uComponents v6? There is a code sample here

    Jeavon

  • Anthony Candaele 1197 posts 2049 karma points
    Dec 12, 2013 @ 09:57
    Anthony Candaele
    1

    Thanks Jeavon, I upgrade from uComponents 5.5.0 to uComponents 6.0.0. I'm using the property converter and everything works fine now:

    @if (Model.Content.HasValue("announcementLink"))
          {
                var urlPicker = Model.Content.GetPropertyValue<UrlPickerState>("announcementLink");
                if (urlPicker.Url != "")
                {
                    <h3>Link</h3>        
                    if (urlPicker.Title != null)
                    {                     
                            <i class="icon-link"></i> <a href="@urlPicker.Url" title="@urlPicker.Title" target="_blank">
                                @urlPicker.Title
                            </a>    
                     }
                     else
                     {                     
                            <i class="icon-link"></i> <a href="@urlPicker.Url" title="@urlPicker.Url" target="_blank">
                                @urlPicker.Url
                            </a>
                     }
                }
            }
    

    the code sample is a great resource!

    greetings,

    Anthony

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 12, 2013 @ 10:05
    Jeavon Leopold
    1

    Awesome, that code sample is my only contribution to the uComponents documentation (so far) :-)

  • Anthony Candaele 1197 posts 2049 karma points
    Dec 12, 2013 @ 13:16
    Anthony Candaele
    0

    I whish there where more code samples like that on uComponents, it was really helpfull. Thanks!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies