Copied to clipboard

Flag this post as spam?

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


  • Nagarjun 36 posts 67 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 89 posts 329 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 3325 posts 11170 karma points MVP 5x 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 36 posts 67 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 5908 posts 22603 karma points MVP 4x 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

  • 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