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 } );
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?
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.
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
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
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
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
Hi Mark,
I'm facing the same issue. Are you able to find some solution for this problem?
/Rizwan
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
anyone resolve this?
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 )
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
is working on a reply...