Copied to clipboard

Flag this post as spam?

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


  • Mark Thomas 34 posts 127 karma points
    Apr 10, 2013 @ 12:52
    Mark Thomas
    0

    Render razor macro from a base extension

    Hi,

    I am getting stuck in to Base Extensions, but can't find any way to render a razor macro and return the html.

    I have so far looked at the umbraco.library.RenderTemplate() and RenderMacroContent() methods , but these don't apply to razor.

    Also tried macro.GetMacro() attempting to parse it myself, where I can get the name of the razor macro, but the MacroContent element is empty.

    I am using Umbraco 4.8.0

    Help!

     

    Mark.

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Apr 11, 2013 @ 09:37
    Dave Woestenborghs
    0

    Why do you want to render a macro from base ?

    dave

  • Mark Thomas 34 posts 127 karma points
    Apr 11, 2013 @ 09:43
    Mark Thomas
    0

    I want to reuse some widgets that we have on one site in another site we are building.

    The idea is to not duplicate the "templating".

    We want the flexibility of having:

    • a simple text document type that return html // this works fine
    • reusing the rendering from Umbraco // not working
    • overriding the rendering in the new site // next step

    Mark.

  • Mark Thomas 34 posts 127 karma points
    Apr 11, 2013 @ 11:56
    Mark Thomas
    101

    I managed to get it done! (Eventually falling over this code snippet http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets/render-razor-scripts-for-emails-and-more)

    Hope this can help someone else in the same situation...

     
    using umbraco; 
    using umbraco.MacroEngines; 
    using umbraco.cms.businesslogic.macro; 

     

          public static string GetOffer(int nodeId)
          {
            var macroEngine = new RazorMacroEngine();

     

            MacroModel model = new MacroModel();
            model.ScriptCode = "";
            model.ScriptLanguage = "cshtml";
            model.ScriptName = "OfferList.cshtml";

     

            return macroEngine.Execute(model, new umbraco.NodeFactory.Node(nodeId));
          }
Please Sign in or register to post replies

Write your reply to:

Draft