Copied to clipboard

Flag this post as spam?

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


  • Rob Watkins 370 posts 702 karma points
    Aug 21, 2019 @ 16:22
    Rob Watkins
    0

    Getting published content in code when there are fields with macros

    I have a custom AJAX service that returns a list of items by using TypedContentAtRoot and selecting the custom result objects.

    This works fine unless there are macros in any of the text fields, in which case I get Cannot render a macro when there is no current PublishedContentRequest

    I actually don't need the macros to run here, so I'd be happy with a solution that didn't bother running them and just returned the comment markup OR one that actually ran them.

    My code is:

            UmbracoHelper uhelper = new UmbracoHelper(UmbracoContext.Current);
    
            var res = uhelper
                .TypedContentAtRoot().First()
                .DescendantsOrSelf()
                .Where(x => x.DocumentTypeAlias == "Event")
                .OrderBy(x => x.GetPropertyValue<MyApp.EventDates>("eventDates").EventDate)
                .Select(x => new MyAppEventDetails(x));
    

    The property values are retrieved using e.g.

    Description = content.GetPropertyValue<string>("eventDescription");
    

    I see there are overloads GetPropertyValue for recursing, but not for disabling macro expansion.

  • 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