Copied to clipboard

Flag this post as spam?

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


  • Neil Pimley 1 post 21 karma points
    Mar 18, 2016 @ 11:39
    Neil Pimley
    0

    Getting custom Media Picker properties from UmbracoContext.Current.ContentCache

    I am creating a gallery using AngularJS to talk to umbraco via the UmbracoApiController. My DocumentType has a String property and a MediaPicker property. I can't retrieve the MediaPicker property from the ContentCache. This is what I have tried:

    public class ContentApiController : UmbracoApiController
    {
        private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
    
        public object GetData(string url)
        {
            try
            {
                var content = !string.IsNullOrEmpty(urlName)
                    ? UmbracoContext.Current.ContentCache.GetByXPath(string.Format(@"//*[@isDoc and @urlName=""{0}""]", url)).FirstOrDefault()
                    : null;
    
                logger.DebugFormat("description exists: {0}", content.HasValue("description"));
                logger.DebugFormat("description value: {0}", content.GetPropertyValue<string>("description"));
    
                logger.DebugFormat("thumbnail exists: {0}", content.HasValue("thumbnail"));
                logger.DebugFormat("thumbnail value: {0}", content.GetPropertyValue<string>("thumbnail"));
    

    my logs show: 2016-03-18 09:49:04,535 [54] DEBUG ContentApiController - description exists: True 2016-03-18 09:49:04,575 [54] DEBUG ContentApiController - description value: A superb .....

    2016-03-18 09:49:04,575 [54] DEBUG ContentApiController - thumbnail exists: False 2016-03-18 09:49:04,576 [54] DEBUG ContentApiController - thumbnail value:

    Is there another way to do this? I don't have the nodeId until I search for the content using the url.

Please Sign in or register to post replies

Write your reply to:

Draft