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 343 posts 593 karma points
    Aug 21, 2019 @ 16:22
    Rob Watkins

    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
                .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.

Please Sign in or register to post replies

Write your reply to: