Copied to clipboard

Flag this post as spam?

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


  • Shane Marsden 13 posts 76 karma points
    Jul 31, 2014 @ 15:34
    Shane Marsden
    0

    Nested macro issue in RTE

    Hi,

    I'm using Umbraco 7.1.4.

    I have a macro that allow a user to select a person and that person gets rendered in the RTE. So the person is a parameter (content picker) It uses a partial view macro file (razor).

    The partial view is really simple for now:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{ var person = Umbraco.Content(Model.MacroParameters["person"]); }
    @person.Picture
    @person.FirstName

    This works fine.

    I am trying to create another macro which renders all of the people in a certain category. I want this to be able to render in the RTE as well. This time the category is the parameter (content picker).

    In this view, I get all of the people then filter by category (excuse the code quality while I try to get this working, I'll clean it up later):

    @using Pcm.Web.Code.Helpers
    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
    var categoryId = Model.MacroParameters["personCategory"];
    var people = new List(Umbraco.Content((int)SpecialNode.People).Children);
    foreach (var person in people) {
    var categories = "," + person.GetPropertyValue("category") + ",";
    if (categories.Contains("," + categoryId + ",")) {
    var umbracoHelper = new UmbracoHelper(UmbracoContext.Current, person);
    @:THIS NEEDS FIXING FOR WITHIN THE RTE - see PersonTeamCategoryList.cshtml
    @:@umbracoHelper.RenderMacro("PersonTeam", new { person = person.Id.ToString() })
    }
    }
    }

    This renders fine on the page, but in the RTE I get an error: Error loading Partial View script (file: ~/Views/MacroPartials/PersonTeamCategoryList.cshtml)

    In the log, it says:

    2014-07-31 14:32:27,424 [61] WARN  umbraco.macro - [Thread 64] Error loading Partial View (file: ~/Views/MacroPartials/PersonTeamCategoryList.cshtml). Exception: System.InvalidOperationException: Cannot render a macro when there is no current PublishedContentRequest.
       at Umbraco.Web.UmbracoHelper.RenderMacro(String alias, IDictionary`2 parameters)
       at ASP._Page_Views_MacroPartials_PersonTeamCategoryList_cshtml.Execute() in c:\dev\Pcm\Pcm.Web\Views\MacroPartials\PersonTeamCategoryList.cshtml:line 23
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
       at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
       at Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer)
       at Umbraco.Web.Mvc.ControllerExtensions.RenderViewResultAsString(ControllerBase controller, ViewResultBase viewResult)
       at Umbraco.Web.Macros.PartialViewMacroEngine.Execute(MacroModel macro, IPublishedContent content)
       at umbraco.macro.LoadPartialViewMacro(MacroModel macro)
       at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)

    This appears to be because PublishedContentRequest is null when rendered in the RTE.

    How can I fix this?

    TIA

Please Sign in or register to post replies

Write your reply to:

Draft