Copied to clipboard

Flag this post as spam?

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


  • Anders Lund 17 posts 38 karma points
    Jun 06, 2011 @ 11:32
    Anders Lund
    0

    Load content from a (Razor-) macro through an ASP.NET generic handler

    Hi

    I have a generic handler and i want to load content from a macro. I am trying with the following piece of code:

    context.Response.Write(umbraco.library.RenderMacroContent("<?UMBRACO_MACRO macroAlias=\"smallCart\"></?UMBRACO_MACRO>", 1051));

    (don't mind the hardcoded ID for now)

    When i hit the handler from my browser, it gives me "Error loading MacroEngine script (file: SmallCart.cshtml)"

    If i place the exact same code in an ASP.NET masterpage or an ASP.NET usercontrol:

    ltrTest.Text = umbraco.library.RenderMacroContent("<?UMBRACO_MACRO macroAlias=\"smallCart\"></?UMBRACO_MACRO>", 1051);

    (outputting it to an ASP.NET literal control for testing)

    it runs my SmallCart.cshtml razor-script and outputs the result just fine.

    Does this relate to something about different contexts between an ASP.NET page and the generic handler...  or any other good suggestions?

    Regards
    Anders

  • Eran Meir 401 posts 543 karma points
    Jun 07, 2011 @ 23:02
  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Jun 08, 2011 @ 02:06
    Anthony Dang
    0

    Anders I tried the same thing a couple weeks ago and ended up giving up and going about it another way. I'm interested to know if something like this can work. My conclusion at the time was that I didn't have time to experiement :)

     

  • Anders Lund 17 posts 38 karma points
    Jun 14, 2011 @ 07:06
    Anders Lund
    0

    Hi Eran and Anthony

    Thank you for your answers. I have had a look at Eran's link and i have been trying to figure this out since my post, but with no success :-(

    I will try to ask at the upcoming Umbraco Codegarden 11. Of course i will post the solution if it exists.

    Regards
    Anders

  • Anders Lund 17 posts 38 karma points
    Jul 19, 2011 @ 15:21
    Anders Lund
    0

    Hi again

    I have now had some time to investigate this futher. It turns out that there is no problem calling an XSLT- or .NET usercontrol based macro.I have also tried to embed my Razor-macro in a .NET usercontrol, but still no luck. No matter what i do with my Razor-macro I get an "Error loading MacroEngine script".

    Therefore it seems that there is a problem with the MacroEngine for Razor combined with the umbraco.library.RenderMacro method.

    I think i will just write an XSLT instead - must be something for the ongoing pillow-fight between the XSLT-lovers and the Razor-rebellion? :-)

  • Jonas Eriksson 930 posts 1825 karma points
    Nov 25, 2011 @ 22:04
    Jonas Eriksson
    0

    Maybe you could try macroEngine.Execute on the razor script instead http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets/render-razor-scripts-for-emails-and-more

    Hth / Jonas

Please Sign in or register to post replies

Write your reply to:

Draft