Copied to clipboard

Flag this post as spam?

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


  • Ashkan Sirous 38 posts 232 karma points
    Aug 11, 2017 @ 11:59
    Ashkan Sirous
    0

    IPublishedContent as Image

    I was digging into Umbraco and I saw a code like this:

       if (media.DocumentTypeAlias == "Image")
                {
                    @Render(media as Image);
                }
    
    @helper Render(Image item)
    {
        <div class="col-xs-6 col-md-3">
            <a href="@item.Url" class="thumbnail">
                <img src="@item.GetCropUrl(width:200, height:200)" alt="@item.Name" />
            </a>
        </div>
    }
    

    The only Image type that I know in Umbraco was Image : HtmlImage which first does not implement IPublishedContent and secondly in obsolete. :)

    What is this Image then?

  • Frans de Jong 550 posts 1862 karma points MVP 4x c-trib
    Aug 11, 2017 @ 14:51
    Frans de Jong
    103

    I think it refers to the image model that's made by modelsbuilder.

    //------------------------------------------------------------------------------
    // <auto-generated>
    //   This code was generated by a tool.
    //
    //    Umbraco.ModelsBuilder v3.0.6.97
    //
    //   Changes to this file will be lost if the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------
    
    using System;
    using System.Collections.Generic;
    using System.Linq.Expressions;
    using System.Web;
    using Umbraco.Core.Models;
    using Umbraco.Core.Models.PublishedContent;
    using Umbraco.Web;
    using Umbraco.ModelsBuilder;
    using Umbraco.ModelsBuilder.Umbraco;
    
    namespace Umbraco.Web.PublishedContentModels
    {
        /// <summary>Image</summary>
        [PublishedContentModel("Image")]
        public partial class Image : PublishedContentModel
        {
    #pragma warning disable 0109 // new is redundant
            public new const string ModelTypeAlias = "Image";
            public new const PublishedItemType ModelItemType = PublishedItemType.Media;
    #pragma warning restore 0109
    
            public Image(IPublishedContent content)
                : base(content)
            { }
    
    #pragma warning disable 0109 // new is redundant
            public new static PublishedContentType GetModelContentType()
            {
                return PublishedContentType.Get(ModelItemType, ModelTypeAlias);
            }
    #pragma warning restore 0109
    
            public static PublishedPropertyType GetModelPropertyType<TValue>(Expression<Func<Image, TValue>> selector)
            {
                return PublishedContentModelUtility.GetModelPropertyType(GetModelContentType(), selector);
            }
    
            ///<summary>
            /// Size
            ///</summary>
            [ImplementPropertyType("umbracoBytes")]
            public string UmbracoBytes
            {
                get { return this.GetPropertyValue<string>("umbracoBytes"); }
            }
    
            ///<summary>
            /// Type
            ///</summary>
            [ImplementPropertyType("umbracoExtension")]
            public string UmbracoExtension
            {
                get { return this.GetPropertyValue<string>("umbracoExtension"); }
            }
    
            ///<summary>
            /// Upload image
            ///</summary>
            [ImplementPropertyType("umbracoFile")]
            public Umbraco.Web.Models.ImageCropDataSet UmbracoFile
            {
                get { return this.GetPropertyValue<Umbraco.Web.Models.ImageCropDataSet>("umbracoFile"); }
            }
    
            ///<summary>
            /// Height
            ///</summary>
            [ImplementPropertyType("umbracoHeight")]
            public string UmbracoHeight
            {
                get { return this.GetPropertyValue<string>("umbracoHeight"); }
            }
    
            ///<summary>
            /// Width
            ///</summary>
            [ImplementPropertyType("umbracoWidth")]
            public string UmbracoWidth
            {
                get { return this.GetPropertyValue<string>("umbracoWidth"); }
            }
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft