Copied to clipboard

Flag this post as spam?

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


  • Kyle Skrinak 272 posts 327 karma points
    Aug 01, 2012 @ 14:17
    Kyle Skrinak
    0

    classing the first/last item of a nav menu in razor

    I'm seeing plenty of xslt-based ways of classing the last unordered list list item, but how to do so in razor? In particular, classing the razor snippet in the distro:

    @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) {
        <ul@Html.Raw(ulClass)>
        @foreach (var item in parent.Children.Where("Visible")) {
          var selected = Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"selected\"" : "";
          <li@Html.Raw(selected)>
            <a href="@item.Url">@item.Name</a>
          </li>
          }
        </ul>
      }
    }
  • Kyle Skrinak 272 posts 327 karma points
    Aug 01, 2012 @ 14:47
    Kyle Skrinak
    0

    Nevermind; figured it out. Changed:

          <li@Html.Raw(selected)>

    to:

         <li@Html.Raw(selected) class="@item.IsLast("last")">
  • 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