Copied to clipboard

Flag this post as spam?

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


  • Nagarjun 43 posts 75 karma points
    Mar 16, 2021 @ 12:05
    Nagarjun
    0

    reading content picker property in Umbraco 8.

    Hi,

    I followed the below url and could not read content picker. Does Umbraco 8 support content picker?

    https://our.umbraco.com/documentation/getting-started/backoffice/property-editors/built-in-property-editors/content-picker/

    @{
        IPublishedContent typedContentPicker = Model.Value<IPublishedContent>("contentPicker"); //contentPicker is the alias name
        if (typedContentPicker != null)
        {
            <p>@typedContentPicker.Name</p>
        }
    }
    
  • AddWeb Solution Pvt. Ltd 109 posts 360 karma points
    Mar 16, 2021 @ 13:18
    AddWeb Solution Pvt. Ltd
    0

    Hello, Nagarjun

    Get the value of content picker property, To use the 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.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Mar 16, 2021 @ 14:14
    Dave Woestenborghs
    0

    Hi Nagarjun,

    You code seems correct. Do you get any errors ?

    And what do you see if you change the code to this :

    @{
        IPublishedContent typedContentPicker = Model.Value<IPublishedContent>("contentPicker"); //contentPicker is the alias name
        if (typedContentPicker != null)
        {
            <p>@typedContentPicker.Name</p>
        }
    else {
    <p>No content found from picker</p>
    }
    }
    
  • Nagarjun 43 posts 75 karma points
    Mar 16, 2021 @ 15:45
    Nagarjun
    0

    Hi Dave,

    Right now, it is not entering into if condition. it always returns null. I use version 8.6.4

    I used sample site that comes with umbraco site and tried to add 'contact' page as content picker in blog page.

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Mar 16, 2021 @ 23:37
    Alex Skrypnyk
    0

    Hi,

    Yes, Umbraco 8 supports content picker.

    Check please that you really have that value, property alias and are you using content picker as datatype?

    Thanks,

    Alex

  • Linx 98 posts 259 karma points
    Dec 08, 2021 @ 18:07
    Linx
    0

    Hi

    Apologies for bringing up this thread but I too used the above link.

    What I am attempting to do is use the content picker where I select a node under the administration area.

    I'm my razor file I am attempting to get the node I selected above.

    Does anyone have a working example?

  • 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