Copied to clipboard

Flag this post as spam?

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


  • Peter Laurie 8 posts 27 karma points
    Jul 02, 2013 @ 20:00
    Peter Laurie
    0

    Alternative to Model.MediaById in Partial View Macros in Umbraco 6

    HI,

    I am porting over the image cropper from a marcosript to a partial view macro in Umbraco 6, and not able to access the media property.

    The HTML Helper for the image cropper looks like this:

    @using System.Xml
    @using System.Xml.Linq
    @using umbraco.MacroEngines

    @functions {    
        public static string GetImageCropperUrl(umbraco.MacroEngines.DynamicXml cropText, string cropName)
     {
           string cropUrl = string.Empty;
            XmlDocument xmlDocument = new XmlDocument();        xmlDocument.LoadXml(cropText.BaseElement.ToString());

         XmlNode cropNode = xmlDocument.SelectSingleNode("descendant::crops/crop[@name='" + cropName + "']");

    if (cropNode != null)
           {
               cropUrl = cropNode.Attributes.GetNamedItem("url").InnerText;
           }
            return cropUrl;
        }
    }

    In the Partial view I am using var articles = Model.Content.Descendants() to iterate through the content pages to build a list of sub pages.

    when it comes to access in the image crop I am using the following code:

    imagePath = @Helpers.ImageHelpers.GetImageCropperUrl(Model.MediaById(art.articleMainImage).crops, "ArticleImage-Main");

    It is the Model.MediaById part that is not working, and I cannot find the correct way to get to the media properties that the html helper function needs. If I create an old style macro, it works fine, but Umbraco are planning to remove macroscripts in the future, so I need to get this working in views.

    Any help would be very appreciated,

    Kind regards,

    Pete

Please Sign in or register to post replies

Write your reply to:

Draft