Copied to clipboard

Flag this post as spam?

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


  • Dibs 202 posts 991 karma points
    Jul 30, 2015 @ 12:10
    Dibs
    0

    Error rendering images

    Dear Umbraco Team

    I am using the following code to display properties of content of a certain Doc Type within the site. i am able to display the url and Name ok, but get error when attempting to display the 'image' property of the Doc type with @Umbraco.Media(item.image).Url.

    @foreach(var item in Model.Content.AncestorOrSelf(1).Descendants().Where(x => x.DocumentTypeAlias == "DocType")) { <a href="@item.Url">@item.Name><img src="@Umbraco.Media(item.Image).Url"></a> }

    Any ideas/guidance good people of Our Umbraco ?

    Thanks Dibs

  • Anders Bjerner 487 posts 2995 karma points MVP 8x admin c-trib
    Jul 30, 2015 @ 16:23
    Anders Bjerner
    100

    Hi Dibs,

    What kind of error do you get? Given your example, item should be of the type IPublishedContent. The interface does not specify an image property.

    If you have added an image property to your document type, you should be able to get the value like:

    @foreach (IPublishedContent item in Model.Content.AncestorOrSelf(1).Descendants().Where(x => x.DocumentTypeAlias == "DocType")) {
       <a href="@item.Url">@item.Name><img src="@Umbraco.Media(item.GetPropertyValue("image")).Url"></a>
    }
    

    Also notice that the property alias is case sensitive - meaning image is not the same as Image.

    Hope this helps ;)

  • Dibs 202 posts 991 karma points
    Aug 11, 2015 @ 10:29
    Dibs
    0

    Thanks Anders

    that gave me a starter for ten, i used the following :

    @foreach(var item in Model.Content.AncestorOrSelf(1).Descendants().Where(x => x.DocumentTypeAlias == "DocType")) 
                        { 
                         var mediaItem = Umbraco.TypedMedia(item.GetPropertyValue("Property")); 
                        <div class="col-xs-6 col-sm-2 col-md-2 center" style="text-align:center;">
                            <a href="@item.Url"><img src="@mediaItem.GetPropertyValue("umbracoFile")">@item.Name</a>
                        </div>
                    }
    

    Thanks Dibs

  • Mike Chambers 636 posts 1253 karma points c-trib
    Aug 24, 2015 @ 20:31
    Mike Chambers
    0

    As .TypedMedia(int id) Given a node ID , returns a IPublishedContent Media entity

    you can simply use mediaItem.Url to fetch the content of "UmbracoFile" this being a reserved core property.

    see https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/ the Working with Media section.

Please Sign in or register to post replies

Write your reply to:

Draft