Copied to clipboard

Flag this post as spam?

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


  • Ryan 34 posts 138 karma points
    Apr 11, 2016 @ 13:06
    Ryan
    0

    Correct usage of EnsurePublishedContentRequestAttribute

    Hi all,

    I'm currently running into the following error when trying to access the rich text property of blog posts containing a macro.

      Cannot render a macro when there is no current PublishedContentRequest.
    

    After a quick search on the forums I found a post in which a user is having a similar issue- accessing RTE with Macro Error

    After reading the post it seems the best way to fix this is to use the EnsurePublishedContentRequestAttribute - the only problem is I'm not completely sure how to use it and I couldn't find a sample anywhere. If anyone could point me in the right direction that would be great!

    Here's a cut down version of my umbraco api controller - I'm running Umbraco 7.3.0

    [HttpGet]
    public async Task<IHttpActionResult>GetBlogs()
    {
       var response = UmbracoContext.ContentCache.GetById(258).Children
                .ToList();
    
       var blogs = response.Select(item => new Blog()
        {
             PostBody = item.GetPropertyValue<string>("bodyContent") //throws Cannot render a macro when there is no current PublishedContentRequest.
    
        }).ToList();
    
       return OK(blogs)      
    }
    

    Thanks

  • 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