Copied to clipboard

Flag this post as spam?

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


  • Brian 15 posts 63 karma points
    Oct 07, 2014 @ 20:57
    Brian
    0

    Display properties from content selected via "Content Picker" data type

    Hello, I'm trying use the content picker data type on a page and then display custom properties from the selected content on that page. In this particular case I have an image in the selected content that I'm trying to display but it looks as though I only have access to ".Url" and ".Name" when reading the documentation.

    Is it possible to display custom properties on these items?

    Here's my set up:

    var author = Umbraco.TypedContent(CurrentPage.author);
    var authorImageId = Umbraco.Media(author.avatar);
    var authorImageUrl = authorImageId.umbracoFile;

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Oct 07, 2014 @ 20:59
    Jeavon Leopold
    0

    Hi Brian,

    You are using the dynamic model (CurrentPage) so you need to use the dynamic Content method instead of the typed TypedContent method.

    e.g.

    var author = Umbraco.Content(CurrentPage.author);
    

    Jeavon

  • Brian 15 posts 63 karma points
    Oct 07, 2014 @ 21:07
    Brian
    0

    Hey Jeavon, thanks for your quick reply on this. I've tried this and get this error:

    Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The call is ambiguous between the following methods or properties: 'Umbraco.Web.UmbracoHelper.Media(params int[])' and 'Umbraco.Web.UmbracoHelper.Media(params string[])'

    Line 77: var author = Umbraco.Content(CurrentPage.author);
    Line 78: var authorImageId = Umbraco.Media(author.avatar); 
    Line 79: var authorImageUrl = authorImageId.umbracoFile;

    Do you see anything else wrong?

    Thanks!

  • Brian 15 posts 63 karma points
    Oct 07, 2014 @ 21:10
    Brian
    0

    Actually, nevermind. I had the content named the same as one of my members and had actually chosen the member instead of the content. Thanks for your help.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Oct 07, 2014 @ 21:11
    Jeavon Leopold
    0

    Could you try this:

    var author = Umbraco.Content(CurrentPage.author);
    
    <p>@author.avatar</p>
    
    if (author.HasValue("avatar"))
    {
        var authorImageId = Umbraco.Media(author.avatar);
        var authorImageUrl = authorImageId.umbracoFile;
    }
    
  • 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