Copied to clipboard

Flag this post as spam?

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


  • René Andersen 238 posts 684 karma points
    Oct 07, 2011 @ 10:41
    René Andersen
    0

    Top Navigation with external URL

    Hi

    Im new to Umbraco and Razor, i have a simple problem where i need to link directly to a external URL / PDF in the top navigation. I have solved the problem in XSLT, but i dont know how to make it work in Razor. Below you can see my XSLT code and below that my Razor code:

    Thanks in advance!

    XSLT:

    <!-- The fun starts here -->
    <div  id="nav">
    <ul>
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
      <li>
    <xsl:choose>
      <xsl:when test="name() = 'externalLinks'">
        <a href="{current()/linkUrl}" target="_blank">
          <xsl:value-of select="@nodeName" />
        </a>
      </xsl:when>
      <xsl:otherwise>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName" />
        </a>
      </xsl:otherwise>
    </xsl:choose>
      </li>
    </xsl:for-each>
    </ul>
    </div>

    </xsl:template>

    </xsl:stylesheet>

    Razor:

    @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) {
        <div id="nav"> <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>
        </div>
      }
    }
  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 07, 2011 @ 12:58
    Dirk De Grave
    0

    René,

    you should be able to do a

    if (@item.NodeTypeAlias == "externalLinks") {...}

    as a replacement for name() = 'externalLinks'

    Cheers,

    /Dirk

     

Please Sign in or register to post replies

Write your reply to:

Draft