Copied to clipboard

Flag this post as spam?

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


  • Owain Williams 481 posts 1413 karma points MVP 7x c-trib
    Feb 17, 2021 @ 07:27
    Owain Williams
    0

    Why can't I use getPropertyValue on a Content Picker?

    I have a content picker on my page which has a value and I have the content picker returning the values I want within my code but when I try and getPropertyValue Name, I get null returned and for some reason the actual LabelTitle throws as a null reference exception even though it does have a value.

    It's so close to working and I don't understand why it's not.

    Any help would be great.

    enter image description here

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Feb 17, 2021 @ 08:37
    Marc Goodson
    1

    Hi Owain

    The name of the node isn't the same as a property that you would add to a document type.

    You can always access the name of the item via the Name property:

    eg

    var label = typedContent.Name;
    

    if you had another property defined on the picked item you could use

    var andAnotherThing = typedContent.GetPropertyValue<string>("andAnotherThing");
    

    (that's if I've understood your question correctly!)

    The thing to be wary of here is, if you are handling all this in an event - then is the item, you have picked guaranteed to be in the Umbraco Published Cache at this stage?

    Also, how is the LabelTitle added as a property? as an extension to IPublishedContent / Modelsbuilder?

    regards

    Marc

  • Owain Williams 481 posts 1413 karma points MVP 7x c-trib
    Feb 17, 2021 @ 08:50
    Owain Williams
    0

    Hi Marc, Thanks for the help.

    So this code is run when a reindex takes place in Examine. The good news is that typedContent.Name worked perfectly for me which is great :)

    The LabelTitle is just a textstring on the genericPageLabel doctype and is added via ModelsBuilder.

    O.

Please Sign in or register to post replies

Write your reply to:

Draft