Copied to clipboard

Flag this post as spam?

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


  • Craig100 1001 posts 2195 karma points c-trib
    4 days ago
    Craig100
    0

    "Cannot render a macro when there is no current PublishedContentRequest" API problem

    Umb V7.15.3

    I have a controller extending UmbracoApiController. It's purpose is to import a page from one site to another and it works absolutely fine except in one particular scenario, if there's a Macro (like an embedded form) in an RTE.

    The following code works fine if the RTE doesn't contain a macro. If it does, then it throws the exception. "Cannot render a macro when there is no current PublishedContentRequest." My code is:-

            returnArticle.bodyText = string.Empty;
            if(theArticle.HasValue("bodyText")) {
                try{
                    var theBodyText = theArticle.GetPropertyValue<string>("bodyText");
                    returnArticle.bodyText = theBodyText;
                } catch (Exception ex) {
                    returnArticle.errorMessage += "ArticleId: " + theArticle.Id + " BodyText Error:" + ex.Message;
                }
    

    returnArticle is my own Model. theArticle is an IPublishedContent.

    This is deep in a controller, far far away from rendering anything. It should just be assigning the RTE's content into the string variable.

    There are quite a few questions in the forum about this but none have a solution. I'd really appreciate a steer even if not a solution.

    Thanks,

    // Craig }

  • Craig100 1001 posts 2195 karma points c-trib
    3 days ago
    Craig100
    100

    Following a nudge from sjb101 on the Slack channel the answer was to refactor "theArticle" by pulling it using the Content Service so it was an IContent rather than an IPublishedContent. So the code is now:-

                returnArticle.bodyText = string.Empty;
                if(theArticle.Properties["bodyText"].Value != null) {
                    try{
                        returnArticle.bodyText = (string)theArticle.Properties["bodyText"].Value;
                    } catch (Exception ex) {
                        returnArticle.errorMessage += "ArticleId: " + theArticle.Id + " BodyText Error:" + ex.Message;
                    }
                }
    

    And works nicely thanks very much :)

    //Craig

Please Sign in or register to post replies

Write your reply to:

Draft