Copied to clipboard

Flag this post as spam?

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


  • JimBob SquarePants 3 posts 23 karma points
    Apr 19, 2011 @ 13:56
    JimBob SquarePants
    0

    Nested macro syntax

    How would I go about displaying a nested macro in razor from within my macro?

     

  • Markus 33 posts 58 karma points
    Apr 19, 2011 @ 17:30
    Markus
    1

    The following works for me:

    @RenderPage("~/macroScripts/myNestedMacro.cshtml")

    You can call that from anywhere in your macro or template. You may also pass specific values to the nested macro by using the @Page:

    for (var item in Model.MyItems)
    {
        Page.MyItem = item;
        @RenderPage("~/macroScripts/NestedScript.cshtml")
    }

    And then in NestedScript.cshtml you can use Page.MyItem:

    @Page.MyItem.Name
  • Tony Kiernan 278 posts 341 karma points
    Sep 27, 2011 @ 20:40
    Tony Kiernan
    0

    Could I pass parameters to that?

  • Tony Kiernan 278 posts 341 karma points
    Jun 20, 2012 @ 19:44
  • Scott Williams 14 posts 71 karma points
    Jun 20, 2012 @ 20:09
    Scott Williams
    0

    To truely render a macro from inside a razor macro you can use the  Razor Components package I recently released. It adds support for rendering macros from other Razor scripts.

    This is specificly for when you want to use real macros, nothing wrong with just using

    @RenderPage("ScriptFileName.chstml")

    but that doesn't handle true macro support.

     

  • Tony Kiernan 278 posts 341 karma points
    Jun 21, 2012 @ 10:40
    Tony Kiernan
    0

    If I try to download that all I'm getting is the README.md file

  • Scott Williams 14 posts 71 karma points
    Jun 21, 2012 @ 10:54
    Scott Williams
    0

    woops I inadvertantly must have marked the redme as the main download, try again now. 

  • Tony Kiernan 278 posts 341 karma points
    Jun 21, 2012 @ 11:04
    Tony Kiernan
    0

    Right off the bat that's not recognising @Library.RenderMacro

  • Scott Williams 14 posts 71 karma points
    Jun 21, 2012 @ 11:10
    Scott Williams
    1

    are you getting any @Library.XXX() intellisense? 

    Are you using

    @inherit umbraco.MacroEngines.DynamicNodeContext 

    ?

    have you added

    @using Tocsoft.Umbraco.RazorComponents

     

  • 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