Copied to clipboard

Flag this post as spam?

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


  • umbracocool 108 posts 197 karma points
    Mar 18, 2013 @ 00:36
    umbracocool
    0

    Why it fails?

    Hello friends!. I do not know what the hell, I'm doing this code, it is giving me error. I'm using version

    Umbraco 4.11.5

    Error loading MacroEngine script (file: TemasGen.cshtml)

     This is the code:

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{

    var idelem = @Parameter.idelem;

    var num = @Parameter.num;

    var countNodes = @Model.NodeById(idelem).Children.Count();

    }

    @if(num < countNodes){

        num = countNodes;

    }

    @if(countNodes > 0){

    <article>

          <h2><a href="#" class="transition-dot3">InformaciĆ³n General</a></h2>

          <ul>

         

    @foreach (var item in @Model.NodeById(idelem).Children.Take(1))

        {

       <li><a href="@item.Url">@item.Name</a></li>

           }

      </ul>

         </article>

    }

    Greetings!

     

  • Carsten Fallesen 35 posts 154 karma points
    Mar 18, 2013 @ 08:19
    Carsten Fallesen
    0

    Hi,

    When you are inside a code region you should not use @, for instance @Parameter should just be Parameter. I also noticed that you have put a Take(1) in the last foreach, this will only give you one item. Is that the intention? I have changed your code a bit to fix the obvious errors:

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{

    var idelem = Parameter.idelem;

    var num = Parameter.num;

    var countNodes = Model.NodeById(idelem).Children.Count();

    }

    @if(num < countNodes){

       num = countNodes;

    }

    @if(countNodes > 0){

    <article>

          <h2><a href="#" class="transition-dot3">InformaciĆ³n General</a></h2>

          <ul>

    @foreach (var item in Model.NodeById(idelem).Children))

        {

      <li><a href="@item.Url">@item.Name</a></li>

           }

      </ul>

         </article>

    }

    If you still have errors try to enable the debugging by adding ?umbDebugShowTrace=true to your url. That will give you more detail on the error. 

    /Carsten

  • umbracocool 108 posts 197 karma points
    Mar 18, 2013 @ 09:07
    umbracocool
    0

    Thank you friend!

    I tried without the "@", but still gives the same error.

    I want to use "Take ()" to limit the results, as chosen in the macro.

    <umbraco:Macro idelem="1073" num="7" Alias="TemasGen" runat="server"></umbraco:Macro>

    Any other solution. Greetings!

  • Carsten Fallesen 35 posts 154 karma points
    Mar 18, 2013 @ 09:23
    Carsten Fallesen
    0

    Did you try debugging by changing the url in the browser by appending  ?umbDebugShowTrace=true 

    That should give you a better error message pinpointing the offending code line. If you could copy the error message in here I am sure we can find the error.

  • Andreas Iseli 150 posts 427 karma points
    Mar 18, 2013 @ 09:27
    Andreas Iseli
    0

    Rebuild your razor code step by step to identify the part where the error occurs and make use of the debugging possibilities. It is hard to identify a problem just by reading your code.

  • umbracocool 108 posts 197 karma points
    Mar 18, 2013 @ 17:23
    umbracocool
    0

    I could identify the error, was that he was checking a string to an integer and so gave the error. I've solved the problem thank you very much to both.

    Using this, I realized the problem.

     

    @num.GetType ();

    @countNodes.GetType ();

     

    BTW. How do I use "?UmbDebugShowTrace=true"?

    Thus for example be used:

     

    http://mysite.com?umbDebugShowTrace=true

    http://mysite.com/home.aspx?umbDebugShowTrace=true

     

    Greetings!

  • 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