Copied to clipboard

Flag this post as spam?

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


  • Thomas 43 posts 123 karma points
    Aug 07, 2018 @ 02:44
    Thomas
    0

    How to get the value of content picker property

    How to find and get the value of umbraco contentpicker? Actually the umbraco return some digit value for that contentpicker, so iwant to convert that to display the exact value on screen How to do this?

  • Louis Ferreira 69 posts 266 karma points
    Aug 07, 2018 @ 05:35
    Louis Ferreira
    100

    Hi Thomas,

    The number that you are seeing returned is the ID of the content/image from the picker.

    To use that ID on your page, you need to write some code similar to

    For content:

    @{
        var page = Umbraco.TypedContent(1234);
    }
    
    <h3>@page.GetPropertyValue<string>("propertyAlias")
    </h3>
    
    @foreach (var child in page.Children) {
        <a href="@child.Url">@child.Name</a>
    }
    

    For Images:

    @{
       var mediaItem = Umbraco.TypedMedia(<ID>); 
       var mediaUrl = mediaItem.Url;
    }
    

    See

    https://our.umbraco.com/documentation/reference/querying/umbracohelper/#working-with-media

    for more details on this.

    Is this what you are looking for?

    Louis

  • Thomas 43 posts 123 karma points
    Aug 07, 2018 @ 05:57
    Thomas
    0

    Hi Louis,

    Thanks for the update.

    Is that possible to the value of contentpicker by using umbraco.library ?

  • Louis Ferreira 69 posts 266 karma points
    Aug 07, 2018 @ 06:40
    Louis Ferreira
    0

    Hi Thomas,

    To fully understand your question, can you give us some context on what you are trying to achieve? This will help us formulate a more accurate answer.

    Louis

  • Thomas 43 posts 123 karma points
    Aug 07, 2018 @ 06:52
    Thomas
    0

    Actually i have tried to get umbraco content page property values for generating xml file. in this some content page has umbraco contentpicker (provide some url) and i want to read this property value.

    already i have handle list of item by using umbraco.library method GetPreValuAsString, so same like this i want to get contentpicker value also

    Ho to do this?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Aug 07, 2018 @ 06:56
    Jan Skovgaard
    0

    Hi Thomas

    Have you tried using the snippet provided in the documentation for the content picker here https://our.umbraco.com/documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Content-Picker2#typed-example ?

    In the example it's shown how to get the name but I suppose you should be able to write .Url to get the url instead for instance.

    Otherwise you should be able to fetch the id/udi and the pass it to @Umbraco.TypedContent like Louis tried to illustrate in the code examples he provided above.

    I hope this helps!

    If not then please try to provide a code example so we can get your context :)

    /Jan

  • Thomas 43 posts 123 karma points
    Aug 07, 2018 @ 07:05
    Thomas
    0

    Hi Jan thanks for the update.

    Is that possible to get the content picker value by using the umbraco library, because when i try to read the node it return some digits (like : 1430) so that i want to try to convert that to appropriate value (liek url)

    So is that possible ?

  • Louis Ferreira 69 posts 266 karma points
    Aug 07, 2018 @ 07:09
    Louis Ferreira
    0

    Like Jan says in his example link...

    @{
        IPublishedContent typedContentPicker = Model.Content.GetPropertyValue<IPublishedContent>("yourContentAlias");
        if (typedContentPicker != null)
        {
            var url = typedContentPicker.Url;                                             
        } 
    }
    
  • Thomas 43 posts 123 karma points
    Aug 08, 2018 @ 09:16
    Thomas
    0

    Hi Louis

    I have tried with umbracohelper like below

    var url = umbracoHelper.NiceUrl(1305);

    Could you please let me know is that correct way? or is there any problem with this

  • Louis Ferreira 69 posts 266 karma points
    Aug 08, 2018 @ 09:35
    Louis Ferreira
    0

    Hi Thomas,

    Without knowing exactly what you are trying to achieve, I can only guess that you are trying to get the url from the content picker control on a page to then place that url in an xml document, right?

    There are a few ways to get url from a content picker control:

    int typedContentPickerId = Model.Content.GetPropertyValue<int>("contentPickerAlias");
        if (typedContentPickerId > 0)
        {
            var url1 = Umbraco.NiceUrl(typedContentPickerId);
            var url2 = Umbraco.TypedContent(typedContentPickerId).Url;
            var url3 = Umbraco.TypedContent(typedContentPickerId).UrlAbsolute();
    
        }
    

    Hope this helps

    Louis

Please Sign in or register to post replies

Write your reply to:

Draft