Copied to clipboard

Flag this post as spam?

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


  • Stephen 767 posts 2273 karma points c-trib
    Feb 04, 2011 @ 12:02
    Stephen
    2

    Razor SiteMap

    This is a followup to http://our.umbraco.org/forum/developers/api-questions/16034-Razor-@helper-in-Umbraco.

    If you want to use DynamicNode in a Razor template, do NOT @using umbraco.MacroEngines as that will cause a name collision with Razor which will then look for global::RazorEngine.Templating in... umbraco.MacroEngines.RazorEngine.Templating (missing the global::).

    Instead, @using ume = umbraco.MacroEngines and then refer to ume.DynamicNode.

    Also, the following SiteMap look works quite well, yet noone has suggested it.

    @helper traverse(dynamic node, int pad) {
        <div style="padding-left: @(pad)px;">
         @node.Name
    @foreach (var n in node.Children) {
    @traverse(n, pad + 8)
    }
    </div>
    }
    @traverse(Model, 0)

    Is there a reason? Performances? Something else?

  • Jonas Eriksson 930 posts 1825 karma points
    Feb 04, 2011 @ 16:05
    Jonas Eriksson
    0

    Hi Stephen! Nice one,

    the reason I added a lambda to it was to be able to filter out stuff like hidden nodes + be able to sort by name. And ul/li's is just the way I'm used to. :-)

    Good with the DynamicNode-workarond!

    Regards,

    Jonas

  • Stephen 767 posts 2273 karma points c-trib
    Feb 04, 2011 @ 16:32
    Stephen
    0

    There should be a way to do in node.Children.Where(foo == 2).OrderBy(n => n.Name) or something equivalent.

    There are patches in the queue to help, I think. Wait and see...

Please Sign in or register to post replies

Write your reply to:

Draft