Copied to clipboard

Flag this post as spam?

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


  • James Lau 37 posts 58 karma points
    Jun 28, 2013 @ 10:32
    James Lau
    0

    call RenderMacroContent() from base error

    I am using umbraco  v 4.11.6 and try to create a base extension to return some html code to a ajax call.

    However, I encounter the follow error 

    UmbracoModuleUmbraco request begins  
    _getNodepageId:1053, contentKey:44260.0012010.001201
    bodyText<?UMBRACO_MACRO macroAlias="Empty" />0.0034760.002275
    pageLoad element "copyright"0.0035760.000100
    pageLoad element "siteName"0.0036400.000063
    pageLoad element "advertisementCodeHome"0.0036810.000041
    pageLoad element "advertisementCodeHome2"0.0037180.000037
    pageLoad element "alertCode"0.0037530.000035
    pageLoad element "lkLabel"0.0037880.000035
    pageLoad element "lkTarget"0.0038250.000036
    pageLoad element "pgTitle"0.0038640.000040
    pageLoad element "relationship"0.0039040.000039
    pageLoad element "sectionHomePage"0.0039390.000035
    pageLoad element "advertisementCode"0.0039740.000035
    pageLoad element "contact"0.0040090.000035
    pageLoad element "sectionRelatedLinks"0.0040450.000035
    pageLoad element "sectionComplementaryText"0.0040840.000039
    pageLoad element "pgTitleHide"0.0041210.000037
    pageLoad element "styles"0.0041560.000036
    pageLoad element "scripts"0.0041930.000037
    pageLoad element "umbracoNaviHide"0.0042310.000038
    pageLoad element "umbracoNaviHideComplementary"0.0042670.000036
    pageLoad element "umbracoNaviHideBreadcrumbs"0.0043030.000035
    templateBegining of parsing rutine...0.0044040.000102
    umbTemplateOutputting item: <?UMBRACO_MACRO macroAlias="Empty" />0.0045130.000109
    templateBegining of parsing rutine...0.0045580.000044
    renderMacroRendering started (macro: Empty, type: 6, cacheRate: 0)0.0046240.000066
    umbracoMacroMacroEngine script added (empty.cshtml)0.0046490.000025
    umbracoMacroLoading IMacroEngine script0.0046640.000015
    macroError loading MacroEngine script (file: empty.cshtml, Type: ''
    Object reference not set to an instance of an object.
      at umbraco.NodeFactory.Node.getCurrentNodeId()
      at umbraco.macro.loadMacroScript(MacroModel macro)
      at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
    0.0049370.000273
    contentError loading MacroEngine script (file: empty.cshtml)

    This is the code trigger the error 

    HttpContext.Current.Trace.Write("content", umbraco.library.RenderMacroContent(node.GetProperty("bodyText").Value, pid));

    empty.cshtml contains two statement only

    @inherits DynamicNodeContext
    @using umbraco.MacroEngines

     

    If I change bodyText to some static text, the base extension work fine. 

    Is it a bug or somthing?

    Thanks for help.

     

     

  • rob 75 posts 170 karma points
    Jul 09, 2013 @ 19:26
    rob
    1

    looks like you are hitting the current page/node issue

    http://labs.vertic.com/2012/05/01/rendering-umbraco-4-content-in-a-service/

    just make sure you set the page id first

    calling 

    int nodeId = 213;
                var razorRendered = umbraco.library.RenderMacroContent("<?UMBRACO_MACRO macroAlias=\"ContentMacroLoader\" runat=\"server\" ColumnName=\"Left Column\" ></?UMBRACO_MACRO>", nodeId);

    always comes back with an error until I added

                int nodeId = 213;
                var contentPage = new umbraco.presentation.Web.UI.ContentPage();
                contentPage.UmbracoNodeId = nodeId;
                var razorRendered = umbraco.library.RenderMacroContent("<?UMBRACO_MACRO macroAlias=\"ContentMacroLoader\" runat=\"server\" ColumnName=\"Left Column\" ></?UMBRACO_MACRO>", nodeId);

    Which seems a bit mad but totally works !

  • Joel Hansen 38 posts 96 karma points
    Sep 22, 2016 @ 13:43
    Joel Hansen
    0

    Thank you rob for providing this answer.

    I agree, it seems mad, but it does the job.

Please Sign in or register to post replies

Write your reply to:

Draft