Copied to clipboard

Flag this post as spam?

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


  • Anton Gildebrand 49 posts 149 karma points c-trib
    Jan 12, 2013 @ 18:11
    Anton Gildebrand
    0

    Using GetProperty-value in while loop

    I am trying to create a Left Navigation Menu macro, using razor. I've run into one small issue though.

    Consider my code

    @{
        var rootnode = Model;
        while (rootnode.Level > 2 && !(bool)rootnode.GetProperty("rootnode")){
            rootnode = rootnode.Parent();
        }
    }

     

    As you can see, it keeps going up from the own page until the level is 2 or the property "rootnode" is true.

    On level 2 pages, this works. But on level 3 pages i get this error:

    Error loading MacroEngine script (file: Leftnav.cshtml)

    What am i doing wrong here, and how do i solve it?

     

     

     

     

     

  • Anton Gildebrand 49 posts 149 karma points c-trib
    Jan 12, 2013 @ 18:49
    Anton Gildebrand
    100

    I was able to solve it. I looked at the type that GetProperty returned, and figured i used the wrong method. After some documentation searching i found the GetPropertyValue, which returns a string value. Is Razor using lazy evaluation? I figured that could be why i worked on level-2 nodes...

     

  • gary 385 posts 915 karma points
    Jan 12, 2013 @ 19:12
    gary
    0

    Hi Anton

    Not 100% sure what you are trying to create, but if you are using 4.11.1 MVC, you can achieve a breadcrumb type navigation by:

    @CurrentPage.Up().NiceUrl()

    If you want full navigation, try

    @{

        var updates = CurrentPage.AncestorOrSelf().Descendants();

    }

     foreach (var item in updates)

                {

                        <a href="@item.NiceUrl()">@item.Name</a>

    }

    This will give you a list.

    Hope this points you in the right direction.

  • Anton Gildebrand 49 posts 149 karma points c-trib
    Jan 12, 2013 @ 19:29
    Anton Gildebrand
    0

    Thank you for your reply Gary.

    Actually its for i side bar navigation. I wanted the children shown in the menu to be the children of the closest mode where the property "rootnode" is set to true. I was able to solve it according to my reply above.

  • Mike Chambers 604 posts 1161 karma points c-trib
    Jan 14, 2013 @ 10:37
    Mike Chambers
    0

    just in case you weren't aware... add ?umbDebugShowTrace=true to your url and make sure your web.config setting has debug enabled.

     <add key="umbracoDebugMode" value="true" />

    Then you can get an error message that is a little more descriptive than the Error loading MacroEngine script (...)

Please Sign in or register to post replies

Write your reply to:

Draft