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) {
        <[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>
      }
    }
  • 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:

         <[email protected](selected) class="@item.IsLast("last")">
Please Sign in or register to post replies

Write your reply to:

Draft