Copied to clipboard

Flag this post as spam?

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


  • Stephen Davidson 216 posts 392 karma points
    Jun 16, 2012 @ 20:06
    Stephen Davidson
    0

    Adapt navigation by level

    Hey all, about time i got myself into Razor and l've inserted the NAVIGATION BY LEVEL razor script wihch works well except i want my home page link to appear also, currently its only page created below my home page which are appeearing.

    Any ideas?

     

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{ 

      var level = String.IsNullOrEmpty(Parameter.Level) ? 1 : int.Parse(Parameter.Level); 

      var ulClass = String.IsNullOrEmpty(Parameter.UlClass) ? "" : String.Format(" class=\"{0}\"", Parameter.UlClass); 

      var parent = @Model.AncestorOrSelf(level);

      if (parent != null) {

        <[email protected](ulClass)>

        @foreach (var item in parent.Children.Where("Visible")) {

          var selected = Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"selected\"" : "";

          <[email protected](selected)>

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

          </li>

          }

        </ul>

      }

    }

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jun 17, 2012 @ 00:17
    Jan Skovgaard
    1

    Hi Stephen

    I'm no Razor wizard (yet) but I think you should do something like this:

    <li>
    <a href="@parent.First().Url">@parent.First().Name</a>
    </li>

    You should place it right before the @foreach statement.

    You can find more inspiration in the cheat sheet if you have not seen it already.

    Hope this helps.

    /Jan

  • Fuji Kusaka 2203 posts 4220 karma points
    Jun 17, 2012 @ 12:07
    Fuji Kusaka
    0

    Hi Stephen,

    Another way round to display your Home page and get the link and highlighted whenever you are on the link you be

    Here am checking if the NodeTypeAlias that is the Document Type "Home".

    const string selectedClass = " class=\"active\"";
        var homeNode = umbraco.library.GetDictionaryItem("Language");
        var homeLang = umbraco.library.GetDictionaryItem("Home");
       
      
      <li@Library.If(Model.NodeTypeAlias == "HOME",  selectedClass)><a href="@homeLang">@homeNode</a></li>

    since am on multilingual website i have some dictionary items here  for the HomeNode and HomeLang.

    var homeNode = Home;
    var homeLang = /en;

     

    Hope it helps, again as Jan said in its previous post have a look at the razor cheat sheet by Peter.

    //fuji

     

Please Sign in or register to post replies

Write your reply to:

Draft