Copied to clipboard

Flag this post as spam?

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


  • mark firth 32 posts 75 karma points
    Dec 09, 2014 @ 14:11
    mark firth
    0

    Render Macro in UmbracoApiController

    Hi,

    I have an application 7.2 that from in UmbracoApiController im trying to pull content from umbraco. One of the fields is a rich text editor that contains a macro. When i try pass the value of the property to my model i get the following error.

    Cannot render a macro when there is no current PublishedContentRequest.

    So the question is how do i ensure there is  a current PublishedContentRequest in the UmbracoApiController?

    My routes in the applicationStart are:

                // initialise routes
                RouteTable.Routes.MapHttpRoute(
                name: "bfoapi",
                routeTemplate: "api/v1/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

    Any help much appreciated.

     

    cheers,

     

    mark

     

     

     

     

     

     

     

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 10, 2014 @ 13:57
    Dave Woestenborghs
    0

    Look at this post : http://our.umbraco.org/forum/umbraco-7/using-umbraco-7/57240-UmbracoApiController-accessing-RTE-with-Macro-Error

    And then in the reply from Shannon. Never tried this before so don't know if it's going to work.

    Maybe you can update us on your progress

    Dave

  • mark firth 32 posts 75 karma points
    Dec 12, 2014 @ 18:14
    mark firth
    0

    Hi Dave,

    Thanks for the reply. I've not got this to work yet. From the link it looks like the same issue.

    From the post:

    "Use theNode.GetProperty("bodyContent").Value; - IIRC this does not use value converters and will return the raw string"

    Does not work.

    "Lastly, the better way to deal with this would just be to create a PublishedContentRequest, but that isn't a public API until 7.2: http://issues.umbraco.org/issue/U4-5627"

    I've downloaded the source for 7.2 and i cannot see how i can create a PublishedContentRequest. Heres the public constructor

            public PublishedContentRequest(Uri uri, RoutingContext routingContext)
            {
                if (uri == null) throw new ArgumentNullException("uri");
                if (routingContext == null) throw new ArgumentNullException("routingContext");

                Uri = uri;
                RoutingContext = routingContext;

                _engine = new PublishedContentRequestEngine(this);

                        RenderingEngine = RenderingEngine.Unknown;
            }

    However i dont know how to provide the routingContext as its constructor is marked as internal. Any ideas how to provide this?

    cheers,

    Mark

     

  • Rizwan ahmed Butt 5 posts 25 karma points
    Mar 05, 2015 @ 13:15
    Rizwan ahmed Butt
    0

    Hi Mark,

    I'm facing the same issue. Are you able to find some solution for this problem?

    /Rizwan 

  • mark firth 32 posts 75 karma points
    Mar 17, 2015 @ 08:43
    mark firth
    0

    Hi Rizan,

    Sorry for the late reply. No i did not get it to work - actually i had some tight deadlines and went around the problem. But i would be very intrested if anyone can get this to work with an examlpe also.

    cheers,

    mark

  • andrew shearer 513 posts 663 karma points
    Mar 20, 2015 @ 05:00
    andrew shearer
    0

    anyone resolve this?

  • Michael Osborn 2 posts 71 karma points
    Sep 28, 2017 @ 22:28
    Michael Osborn
    0

    Hey Guys, I understand that this is mega late in the game but this is how I am getting around the issues ( be gentle with me its my first post )

    var umbracoHelper = new UmbracoHelper(UmbracoContext);
    var page = umbracoHelper.Content( Id );
    
    UmbracoContext.PublishedContentRequest = 
                    new PublishedContentRequest(url,  UmbracoContext.RoutingContext);
    
     UmbracoContext.PublishedContentRequest.Prepare();
    
     var publishedContent = UmbracoContext.PublishedContentRequest.PublishedContent;
    

    I have a form macro in content that I tested this with and it seems to render it just fine.

    Id = Id of content url = Uri of content that I make up from page and Request.RequestUri

  • 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