Copied to clipboard

Flag this post as spam?

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


  • Psib3r 70 posts 119 karma points
    Jul 09, 2013 @ 12:59
    Psib3r
    0

    sitemap

    I have the following script

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{    
    @* Walk up the tree from the current page to get the root node *@
      var rootNode = Model.AncestorOrself(1);
    }
    
    @*Render the sitemap by passing the root node to the traverse helper*@
    <div class="sitemap"> 
        @traverse(@Model.AncestorOrSelf())
    </div>
    
    
    
    @*Helper method to travers through all descendants*@
    @helper traverse(dynamic node)
    {
    @*Select visible children *@
      var items = node.Children.Where("Visible");
    
    @*If any items are returned, render a list *@
      if (items.Any())
      { 
      <ul>
        @foreach (var item in items)
        {
          if (item.hasProperty("siteMapIgnore"))
          {
            if (item.getProperty("siteMapIgnore") != "1")
            {
          <li>
            <a href="@item.Url">@item.Name</a>
    
            @*Run the traverse helper again *@
            @traverse(item)
    
          </li>
            }
          }
        }
      </ul>
      }
    }

    But all i get on the page is Error loading MacroEngine script (file: SiteMap.cshtml)

    Can someone let me know if there is a problem with version 6 and this script?  

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jul 09, 2013 @ 15:43
    Jeavon Leopold
    101

    Have you just upgraded to v6?

    The Razor engine was a little more forgiving in v4 (I have no idea why) but anyway I think your only issue is now an additonal @

     @traverse(@Model.AncestorOrSelf())

     Should be

     @traverse(Model.AncestorOrSelf())

    In v4 this would have worked but in v6 it will kick up an error.

    Hope that sorts it for you?

    Jeavon

  • Psib3r 70 posts 119 karma points
    Jul 09, 2013 @ 16:05
    Psib3r
    0

    Working, great, thank you

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jul 09, 2013 @ 16:17
    Jeavon Leopold
    0

    Just a very small missing capital letter in AncestorOrSelf, here is fully working version:

     @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{    
    @* Walk up the tree from the current page to get the root node *@
      var rootNode = Model.AncestorOrSelf(1);
    }
    
    @*Render the sitemap by passing the root node to the traverse helper*@
    <div class="sitemap"> 
        @Traverse(rootNode)
    </div>
    
    <p>ssdsdsd</p>
    @*Helper method to travers through all descendants*@
    @helper Traverse(dynamic node)
    {
    @*Select visible children *@
        var items = node.Children.Where("Visible");
    @*If any items are returned, render a list *@
      if (items.Any())
      { 
      <ul>
       @foreach (var item in items)
        {
          if (item.hasProperty("siteMapIgnore"))
          {
            if (item.getProperty("siteMapIgnore") != "1")
            {
          <li>
            <a href="@item.Url">@item.Name</a>
    
            @*Run the traverse helper again *@
            @Traverse(item)
    
          </li>
            }
          }
        }
      </ul>
      }
    }

     

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 02, 2013 @ 14:28
    Anthony Candaele
    0

    I try to use the default Sitemap script in my Umbraco 6.1.5 install. I have removed the @ and changed AncestorOrself to AncestorOrSelf, but it's still not working for some reason:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{    
        @* Walk up the tree from the current page to get the root node *@
        var rootNode = Model.AncestorOrSelf(1);
     }
    
    @*Render the sitemap by passing the root node to the traverse helper*@
        <div class="sitemap"> 
        @traverse(Model.AncestorOrSelf())
    </div>
    
    
    
    @*Helper method to travers through all descendants*@
    @helper traverse(dynamic node){
    
    @*If a MaxLevelForSitemap parameter is passed to the macro, otherwise default to 4 levels*@
    var maxLevelForSitemap = String.IsNullOrEmpty(Parameter.MaxLevelForSitemap) ? 4 :      int.Parse(Parameter.MaxLevelForSitemap); 
    
    @*Select visible children *@
    var items = node.Children.Where("Visible").Where("Level <= " + maxLevelForSitemap);
    
    
    @*If any items are returned, render a list *@
    if (items.Any()) { 
       <ul>
       @foreach (var item in items) {
          <li class="[email protected]">
                    <a href="@item.Url">@item.Name</a>
    
             @*Run the traverse helper again *@
                    @traverse(item)
                </li>
       }
       </ul>
        }
    }
    
  • Anthony Candaele 1197 posts 2049 karma points
    Oct 02, 2013 @ 14:31
    Anthony Candaele
    0

    I ran the debugger, and the code breaks at this line:

    if (items.Any())
    

    the error message is:

    'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Any'
    
  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Oct 02, 2013 @ 14:48
    Dennis Aaen
    2

    Hi Anthony,

    Have you tried to pass the rootNode variable into it like this:

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{    
       
    @*Walk up the tree from the current page to get the root node *@
       
    var rootNode =Model.AncestorOrself(1);
    }

    @*Render the sitemap by passing the root node to the traverse helper*@
    <div class="sitemap">
       
    @traverse(rootNode)
    </div>



    @*Helper method to travers through all descendants*@
    @helper traverse(dynamic node){

    @*If a MaxLevelForSitemap parameter is passed to the macro, otherwise default to 4 levels*@
    var maxLevelForSitemap = String.IsNullOrEmpty(Parameter.MaxLevelForSitemap) ? 4 : int.Parse(Parameter.MaxLevelForSitemap);

    @*Select visible children *@
    var items = node.Children.Where("Visible").Where("Level <= " + maxLevelForSitemap);

    @*If any items are returned, render a list *@
    if (items.Any()) {
       <ul>
                @foreach (var item in items) {
              <li class="[email protected]">
                        <a href="@item.Url">@item.Name</
    a>

                 
    @*Run the traverse helper again *@
                       
    @traverse(item)
                   
    </li>
                }
       </
    ul>
       
    }
    }

    Don´t know if this do any difference for you.

    /Dennis

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 02, 2013 @ 15:16
    Anthony Candaele
    0

    Dennis,

    I tried your update by adding rootNode to the @travers method, but the code still breaks at the same line as mentioned above.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Oct 02, 2013 @ 16:23
    Jeavon Leopold
    1

    Hi Anthony,

    I'm pretty sure this is a bug as Model.AncestorOrSelf() is always returning 0 but I'm just looking into the exact point it might have changed. As a workaround I have found that this should work:

    dynamic rootNode = CurrentModel.AncestorOrSelf();
    

    Thanks,

    Jeavon

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 02, 2013 @ 16:41
    Anthony Candaele
    0

    Hi Jeavon,

    I change my code with your update, it now looks like this:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{    
        @* Walk up the tree from the current page to get the root node *@
        @*var rootNode = Model.AncestorOrSelf(1); *@
        dynamic rootNode = CurrentModel.AncestorOrSelf();
    }
    
    @*Render the sitemap by passing the root node to the traverse helper*@
    <div class="sitemap"> 
        @traverse(rootNode)
    </div>
    
    
    
    @*Helper method to travers through all descendants*@
    @helper traverse(dynamic node){
    
    @*If a MaxLevelForSitemap parameter is passed to the macro, otherwise default to 4 levels*@
    var maxLevelForSitemap = String.IsNullOrEmpty(Parameter.MaxLevelForSitemap) ? 4 :        int.Parse(Parameter.MaxLevelForSitemap); 
    
    @*Select visible children *@
    var items = node.Children.Where("Visible").Where("Level <= " + maxLevelForSitemap);
    
    
    @*If any items are returned, render a list *@
    if (items.Any()) { 
       <ul>
            @foreach (var item in items) {
          <li class="[email protected]">
                    <a href="@item.Url">@item.Name</a>
    
             @*Run the traverse helper again *@
                    @traverse(item)
                </li>
            }
       </ul>
        }
    }
    

    However, the code still breaks at the line:

    if (items.Any())
    

    Thanks for your help, Anthony

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Oct 02, 2013 @ 17:10
    Jeavon Leopold
    1

    Hi Anthony,

    What output do you get if you try this snippet?

    @{    
        var rootNode1 = Model.AncestorOrself();    
        dynamic rootNode2 = CurrentModel.AncestorOrSelf();
    
        <p>@rootNode1.Id : @rootNode2.Id</p>   
    }
    

    Jeavon

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Oct 02, 2013 @ 18:13
    Jeavon Leopold
    1

    Hey Anthony,

    Are you using a clean v6.1.5 install or a upgraded installation?

    Jeavon

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 02, 2013 @ 19:29
    Anthony Candaele
    0

    I'm using a clean v6.1.5 install

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Oct 02, 2013 @ 21:57
    Jeavon Leopold
    1

    Odd, do you have any Nuget packages installed that have added dlls to the bin folder that could be conflicting with the Linq extensions?

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Oct 03, 2013 @ 09:59
    Dennis Aaen
    1

    Hi Anthony and Jeavon,

    I just setup an clean installation of Umbraco 6.1.5, and do the test that  Jeavon suggested.

    @{    
       
    var rootNode1 =Model.AncestorOrself();    
        dynamic rootNode2
    =CurrentModel.AncestorOrSelf();

       
    <p>@rootNode1.Id:@rootNode2.Id</p>  
    }

    It turns out that the @rootNode1.Id  retuns 0 and the @rootNode2.Id actually returns the id of the homepage.

    I hope this can be useful information for both of you.

    /Dennis

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Oct 03, 2013 @ 10:08
    Dennis Aaen
    2

    Oh I made a mistake in  my previous post.

    The mistake is: the small s in self, so it should be AncestorOrSelf

    var rootNode1 =Model.AncestorOrself();  

    And when I change it to:

    var rootNode1 =Model.AncestorOrSelf();  

    It turns out that the to lines of code returns the same ID. In my case 1051.

    /Dennis

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Oct 03, 2013 @ 10:25
    Jeavon Leopold
    1

    Dennis, that is awesome, drove me a little crazy yesterday! The ficklety of dynamics, although I think it should throw a error really! However I don't think this is the issue affecting Anthony....

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 03, 2013 @ 19:04
    Anthony Candaele
    0

    Hi Jeavon,

    Sorry, I'm not at my office right now. I'll let you know next Monday.

    greetings,

    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 03, 2013 @ 19:11
    Anthony Candaele
    0

    @Dennis, I tried your suggestions, but none is solving the problem. I tried

        var rootNode = Model.AncestorOrSelf();

        var rootNode = Model.AncestorOrSelf(1);

        var rootNode = Model.AncestorOrSelf(2);

     

    greetings,

    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 08, 2013 @ 09:16
    Anthony Candaele
    0

    Hi Jeavon,

    Sorry for the delay. Just tested your snippet:

    @{    
    var rootNode1 = Model.AncestorOrself();    
    dynamic rootNode2 = CurrentModel.AncestorOrSelf();
    
    <p>@rootNode1.Id : @rootNode2.Id</p>   
    }
    

    The output is:

    0 : 1049
    

    greetings,

    Anthony

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Oct 08, 2013 @ 09:24
    Jeavon Leopold
    1

    Hi Anthony,

    I think that was a red herring as there was typo in the first one as the s in Self should be capitalised. It seems older Umbraco versions forgave the casing but not for some time.

    Did you check if you had and other non-Umbraco dlls in your bin folder?

    Jeavon

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Oct 08, 2013 @ 09:30
    Dennis Aaen
    1

    Hi Anthony,

    It´s because of a small spell issue. the reason why you get the 0 : 1049 is because of wrong spelling AncestorOfSelf.

    @{    
    var rootNode1 =Model.AncestorOrself();    
    dynamic rootNode2
    =CurrentModel.AncestorOrSelf();

    <p>@rootNode1.Id:@rootNode2.Idp>  
    }

    If you change it to this:

    @{    
    var rootNode1 =Model.AncestorOrSelf();    
    dynamic rootNode2
    =CurrentModel.AncestorOrSelf();

    <p>@rootNode1.Id:@rootNode2.Idp>  
    }

    It´s should output the same id´s even if you are using rootNode1 or rootNode2 you should get this:

    1049:1049

    I think that Umbraco should throw an error based on incorrect spelling of the AncestorOrSelf axis.

    /Dennis

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 08, 2013 @ 10:08
    Anthony Candaele
    0

    Hi Dennis,

    I tested your script:

    @{    
    var rootNode1 =Model.AncestorOrSelf();    
    dynamic rootNode2 =CurrentModel.AncestorOrSelf();
    
    <p>@rootNode1.Id:@rootNode2.Id</p>   
    }
    

    this gives me indeed the output:

    1049:1049
    

    Thanks,

    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 08, 2013 @ 10:39
    Anthony Candaele
    0

    Hi Guys,

    the above code gives me the rootnode now, but my code is still crashing on:

    if (items.Any()) { 
    ...
    }
    

    the error message in Visual Studio is:

    'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Any'
    

    'items' is created on this code:

    @*Helper method to travers through all descendants*@
    @helper traverse(dynamic node){
    
    @*If a MaxLevelForSitemap parameter is passed to the macro, otherwise default to 4 levels*@
    var maxLevelForSitemap = String.IsNullOrEmpty(Parameter.MaxLevelForSitemap) ? 4 :         int.Parse(Parameter.MaxLevelForSitemap); 
    
    @*Select visible children *@
    var items = node.Children.Where("Visible").Where("Level <= " + maxLevelForSitemap);
    

    I'm running this code in a MacroScript (not a Partial View Macro File)

    Does anyone has an idea why this is not working?

    thanks,

    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 08, 2013 @ 11:25
    Anthony Candaele
    0

    ok, solution was easier then I thought, just replaced the line:

    if (items.Any()) { .... }
    

    with

    if (items.Count() > 0 ) { .... }
    

    now the sitemap.cshtml script works :)

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 08, 2013 @ 11:33
    Anthony Candaele
    0

    for completeness, and maybe someone else can make use of it, this is my entire MacroScript file for Sitemap.cshtml:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{    
    
        var rootNode1 =Model.AncestorOrSelf();    
        dynamic rootNode2 = CurrentModel.AncestorOrSelf();
    
    
    }
    
    @*Render the sitemap by passing the root node to the traverse helper*@
    <div class="sitemap"> 
        @traverse(rootNode2)
    </div>
    
    
    
    @*Helper method to travers through all descendants*@
    @helper traverse(dynamic node){
    
    @*If a MaxLevelForSitemap parameter is passed to the macro, otherwise default to 4 levels*@
    var maxLevelForSitemap = String.IsNullOrEmpty(Parameter.MaxLevelForSitemap) ? 4 :       int.Parse(Parameter.MaxLevelForSitemap); 
    
    @*Select visible children *@
    var items = node.Children.Where("Visible").Where("Level <= " + maxLevelForSitemap);
    
    
    @*If any items are returned, render a list *@
    if (items.Count() > 0) { 
        <ul>
              @foreach (var item in items) {
                <li class="[email protected]">
              <a href="@item.Url">@item.Name</a>
    
                  @*Run the traverse helper again *@
              @traverse(item)
                </li>
              }
       </ul>
    }
    }
    
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Oct 08, 2013 @ 12:09
    Jeavon Leopold
    1

    Hi Anthony,

    That is odd, I can't remember exactly which version of DynamicNode introduced the .Any method but it certainly was a long time ago, it really seems that you have a old version of umbraco.MacroEngines.dll, maybe check your assembly version, in Umbraco v6.1.6 I have 1.0.5021.24871 and in v6.1.5 I have 1.0.4993.19251.

    Jeavon

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 08, 2013 @ 14:55
    Anthony Candaele
    0

    Hi Jeavon,

    I checked the version of umbraco.MacroEngines.dll

    it's : 1.0.4993.19251

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Oct 09, 2013 @ 21:13
    Jeavon Leopold
    1

    Anthony, one suggestion, maybe combine your Where into one e.g.

    var items = node.Children.Where("Visible && Level <= @0", maxLevelForSitemap);
    
  • Anthony Candaele 1197 posts 2049 karma points
    Oct 10, 2013 @ 08:52
    Anthony Candaele
    0

    Hi Jeavon, thanks for the suggestion!

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Oct 10, 2013 @ 10:09
    Jeavon Leopold
    0

    Hi Anthony,

    Ok, so the problem is caused by WebGrease.dll, if you remove it from the bin, you should find that .Any() works again.

    Now, to think about why that might be.....

    Jeavon

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Oct 10, 2013 @ 10:22
    Jeavon Leopold
    1

    Some good news, updating WebGrease from v1.3.0 to current v1.5.2 fixes the issue for me!

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 10, 2013 @ 10:40
    Anthony Candaele
    0

    Oh I see, where can I find WebGrease v1.5.2 ?

    Thanks,

    Anthony

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Oct 10, 2013 @ 10:45
    Jeavon Leopold
    1

    NuGet Did you add it through a bundling package (Optimus) or similar? You may need an assembly redirection depending on how the dependent package was compiled.

    If you don't use NuGet to update, you will also have to update Antlr3.Runtime.dll as WebGrease is dependent on that.

    Thanks,

    Jeavon

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 10, 2013 @ 10:53
    Anthony Candaele
    0

    Hi Jeavon,

    Yes, I installed Optimus. There was a problem with that package for Umbraco 6.1.5: http://our.umbraco.org/projects/developer-tools/optimus/computer-says-no/45119-no-styles-rendered

    This might explain the problem with Optimus, I'll inform Tim (Geyssens) about it.

    greetings,

    Anthony

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Oct 10, 2013 @ 11:00
    Jeavon Leopold
    1

    Not sure if it's related, but it could be.

    I actually already have a fork of Optimus where I have upgraded the Bundling.Core which includes upgrading WebGrease https://github.com/Jeavon/BundlingAndMinificationForTheMasses

    Jeavon

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 10, 2013 @ 11:11
    Anthony Candaele
    0

    How can I install this Optimus fork over my existing Optimus installation ?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Oct 10, 2013 @ 11:44
    Jeavon Leopold
    0

    I will send you a new package :-)

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 10, 2013 @ 13:00
    Anthony Candaele
    0

    Cool!

Please Sign in or register to post replies

Write your reply to:

Draft