Copied to clipboard

Flag this post as spam?

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


  • ibrahim Nada 12 posts 102 karma points
    Aug 27, 2017 @ 17:39
    ibrahim Nada
    0

    Content Picker, Picked An Unpublished Node

    Hello Guys i have a weird a question , lets say i have a node content picker and i assigned it to a specific node then i unpublished that node so my Content Picker Propriety Has An unpublished Node And my website keeps Throwing an exception dose anyone ran into similar issue ? the user is really naive and i need to handle it from my side any thoughts ?

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Aug 28, 2017 @ 10:45
    Alex Skrypnyk
    0

    Hi Ibrahim

    Can you show your code?

    You have to handle the situation when the content picker is containing unpublished node.

    Thanks,

    Alex

  • ibrahim Nada 12 posts 102 karma points
    Aug 28, 2017 @ 10:46
    ibrahim Nada
    0

    How to Do So ?

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Aug 28, 2017 @ 10:47
    Alex Skrypnyk
    0

    Check selected node for null.

    Can you show how do you render the page and where do you have an exception?

    Thanks,

    Alex

  • ibrahim Nada 12 posts 102 karma points
    Aug 28, 2017 @ 10:49
    ibrahim Nada
    0
               <p class="p2">@CurrentPage.sectionNumber6.Name</p>
                    <a href="@CurrentPage.sectionNumber6.Url"><button>More</button></a>
    

    The sectionNumber6 is a Content Picker

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Aug 28, 2017 @ 10:53
    Alex Skrypnyk
    100

    Try to use this code:

    @if (Umbraco.AssignedContentItem.GetPropertyValue<IPublishedContent>("sectionNumber6") != null)
    {
        <p class="p2">@CurrentPage.sectionNumber6.Name</p>
        <a href="@CurrentPage.sectionNumber6.Url"><button>More</button></a>
    }
    
  • ibrahim Nada 12 posts 102 karma points
    Aug 28, 2017 @ 11:00
    ibrahim Nada
    0

    It worked Perfectly Thanks A lot
    i have Put them In try catch Statement Do you think i should change them in sake if a better practice or what ?

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Aug 28, 2017 @ 12:09
    Alex Skrypnyk
    0

    The better way will be like that:

    @{
        var itemValue = Umbraco.AssignedContentItem.GetPropertyValue<IPublishedContent>("sectionNumber6");
        if (itemValue != null)
        {
            <p class="p2">@itemValue.Name</p>
            <a href="@itemValue.Url"><button>More</button></a>
        }
    }
    
  • 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