Copied to clipboard

Flag this post as spam?

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


  • Biagio Paruolo 1619 posts 1912 karma points c-trib
    Mar 22, 2011 @ 17:53
    Biagio Paruolo
    0

    How to read level of node?

    How Can I read level of current node? So if node level is 1, I don't display some info.

    Thank you

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Mar 22, 2011 @ 18:05
    Sebastiaan Janssen
    0

    .Level works, something like this:

    @{
        var rootNode = Model.AncestorOrSelf(1);
        foreach (var node in rootNode.Descendants())
        {
            if(node.Level == 2)
            {
                <p>@node.Name</p>
            }
            else {
                <p>@node.CreateDate</p>
            }
        }
    }
    
  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Mar 22, 2011 @ 18:11
    Sebastiaan Janssen
    0

    Oh just noticed that you wanted the current node, that's just:

    Model.Level

  • Biagio Paruolo 1619 posts 1912 karma points c-trib
    Mar 22, 2011 @ 18:15
    Biagio Paruolo
    0

    Good...works..

      <umbraco:Macro  runat="server" language="cshtml">
    @inherits umbraco.MacroEngines.DynamicNodeContext


                    @if (Model.Level>1) {
                    
    <ul>
      @foreach(var level in @Model.Ancestors().Where("Visible"))
      {
        <li><a href="@level.Url">@level.Name</a> > </li>
      }
      <li><b>@Model.Name</b></li>
    </ul>
                    }           
                    
    </umbraco:Macro>


    Other question: Which is the declaration of vars in upper macro? I try with var livello = @Model.Level but I've error that "livello is out of scope".

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Mar 22, 2011 @ 18:21
    Sebastiaan Janssen
    0

    I don't know what you want to do, but if you create the livello variable inside the foreach then you can't access it outside of the foreach.. 

  • Biagio Paruolo 1619 posts 1912 karma points c-trib
    Mar 22, 2011 @ 18:48
    Biagio Paruolo
    0

    I declare var before @if. Then I wish to use it into if condition.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Mar 22, 2011 @ 20:14
    Sebastiaan Janssen
    0

    This does not work?

    var livello = 1;
    
    @if (Model.Level > livello) {               
        <ul>
          @foreach(var level in @Model.Ancestors().Where("Visible"))
          {
            <li><a href="@level.Url">@level.Name</a> > </li>
          }
          <li><b>@Model.Name</b></li>
        </ul>
    }
Please Sign in or register to post replies

Write your reply to:

Draft