Copied to clipboard

Flag this post as spam?

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


  • Suja Shyam 14 posts 34 karma points
    Nov 07, 2011 @ 13:06
    Suja Shyam
    0

    Changing the navigation of sub-menu items

    I have a XSLT macro for top navigation. Now I need to change certain links to navigate to different umbraco pages. I shall share my xslt file here

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


      <xsl:output method="xml" omit-xml-declaration="yes"/>
     
      <xsl:param name="currentPage"/>

      <xsl:variable name="source" select="/macro/source"/>

      <xsl:template match="/">   
        <xsl:variable name="pages" select="umbraco.library:GetXmlNodeById($source)/*[@isDoc and string(umbracoNaviHide) != '1' and string(includeInMainNavigation) = '1']"/>
        <xsl:variable name="pagesNodeSet" select="msxml:node-set($pages)"/>
     
        <div id="main_navigation" class="jqueryslidemenu unitPng">
          <ul>
            <li><a href="/">Home</a></li>
            <xsl:for-each select="$pagesNodeSet">
              <xsl:sort select="./@sortOrder" data-type="text" order="ascending"/>
              <li>
                <a href="{umbraco.library:NiceUrl(./@id)}"><xsl:value-of select="./title"/></a>
                <xsl:if test="count(./*[@isDoc and string(umbracoNaviHide) != '1' and string(includeInMainNavigation) = '1']) &gt; 0">
                  <ul class="sub-menu">
                    <xsl:for-each select="./*[@isDoc and string(umbracoNaviHide) != '1' and string(includeInMainNavigation) = '1']">
                      <xsl:sort select="./@sortOrder" data-type="text" order="ascending"/>
                      <li><a href="{umbraco.library:NiceUrl(./@id)}"><xsl:value-of select="./title"/></a></li>              
                    </xsl:for-each>
                  </ul>
                </xsl:if>
              </li>
            </xsl:for-each>
          </ul>
        </div>
     
      </xsl:template>

    </xsl:stylesheet>

    How can I edit this XSLT file to change the navigation of a sub-menu item Home -> Link1 -> AAA to Home -> Link2 -> ZZZ. i.e. when I click AAA it should show page for ZZZ. Also a sub-menu item Home -> Link2 -> YYY should load an external website in a new window.  Hope am successfull making my scenario clear.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 07, 2011 @ 13:21
    Dirk De Grave
    0

    Add your content node structure (eg a screenshot) so people actually understand what you're trying to do... I can't figure out what you want based on your textual description. (A pic says more than a 1000 words...)

    Looking forward to your info.

    Cheers,

    /Dirk

  • Suja Shyam 14 posts 34 karma points
    Nov 08, 2011 @ 07:11
    Suja Shyam
    0

    Ok Dirk, I shall share the screenshot. 

     

  • Bert 128 posts 251 karma points
    Nov 08, 2011 @ 09:32
    Bert
    0

    Just get those chidlinks an extra property, like explained in the wiki. But it might be better to just create an alternative document type for external links and use that one for documents that have to redirect outside your site.

    And for the internal redirect umbraco has a nifty build in mechanism: umbracoRedirect and umbracoInternalRedirectId.
     

  • Suja Shyam 14 posts 34 karma points
    Nov 09, 2011 @ 07:58
    Suja Shyam
    0

    Thanks Bert. Internal redirect worked well. To redirect to an external link, I created a document type 'EnternalRedirect' along with the template for it. Then I modified 'ExternalRedirect' template with code provided in the wiki. This is my modified template code

    <%@ Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>
    <%@ Import Namespace="umbraco.BusinessLogic" %>
    <%@ Import Namespace="umbraco.cms.businesslogic.web" %>
    <%@ Import Namespace="umbraco.presentation.nodeFactory" %>
    <script runat="server">
      void Page_Load(object sender, System.EventArgs e)
      {
        Response.Redirect("http://www.google.com");
      }
    </script>

    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
     
    </asp:Content>

    I want google to open up in a new window or tab to replace Response.Redirect(). How can this be achieved?

  • Bert 128 posts 251 karma points
    Nov 09, 2011 @ 09:51
    Bert
    0

    Isn't it easier to just create an external link when you are parsing the navigation out? So in your navigation macro you either have the current case or you create an external link, no redirects needed ;)

    <a href="nodepropertyurl" target="_blank"> nodename </a>
  • Suja Shyam 14 posts 34 karma points
    Nov 09, 2011 @ 10:35
    Suja Shyam
    0

    Sorry Bert am totally new this Umbraco. I have hardly a week experience working on this. So can you explain more on the changes in the macro. My macro looks like:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
      <!ENTITY nbsp "&#x00A0;">
    ]>
    <xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:msxml="urn:schemas-microsoft-com:xslt"  xmlns:umbraco.library="urn:umbraco.library"  xmlns:msxsl="urn:schemas-microsoft-com:xslt"  xmlns:math="http://exslt.org/math" exclude-result-prefixes="msxml umbraco.library math">

      <xsl:output method="xml" omit-xml-declaration="yes" />

      <xsl:param name="currentPage"/>

      <xsl:variable name="source" select="/macro/source"/>

      <xsl:template match="/">   
        <xsl:variable name="productRanges" select="umbraco.library:GetXmlNodeById($source)/*[@isDoc and string(umbracoNaviHide) != '1']"/>
        <xsl:variable name="productRangesNodeSet" select="msxml:node-set($productRanges)"/>
       
        <div class="widget scg_widget webtreats_subnav_widget">
          <h3 class="widgettitle">By Product</h3>
          <ul>       
            <li>
              <xsl:attribute name="class">
                <xsl:text>page_item"</xsl:text>
                <xsl:if test="$currentPage/@nodeName = 'Products'">
                  <xsl:text> current_page_item</xsl:text>
                </xsl:if>        
              </xsl:attribute>              
              <a href="/products.aspx" title="">Overview</a>
            </li>       
            <xsl:for-each select="$productRanges">
              <li>
                <xsl:attribute name="class">
                  <xsl:text>page_item"</xsl:text>
                  <xsl:if test="$currentPage/@id= ./@id">
                    <xsl:text> current_page_item</xsl:text>
                  </xsl:if>       
                </xsl:attribute>             
                <a href="{umbraco.library:NiceUrl(./@id)}" title=""><xsl:value-of select="./title" /></a>
              </li>           
            </xsl:for-each>
          </ul>
        </div>    
      </xsl:template>

    </xsl:stylesheet>

     

    Am not able to understand where the <a> is to be added. Please help me on this.

  • Bert 128 posts 251 karma points
    Nov 09, 2011 @ 10:55
    Bert
    0

    Guess you want something like this (default navigation prototype xslt with some additions)

    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul>
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
      <li>
       
        <xsl:if test="@nodeName != 'ExternalLinkDocType'">
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
            <!-- we're under the item - you can do your own styling here -->
            <xsl:attribute name="class">selected</xsl:attribute>
          </xsl:if>
          <xsl:value-of select="@nodeName"/>
        </a>
        </xsl:if>
        <xsl:if test="@nodeName = 'ExternalLinkDocType'">

        <a href="@urlproperty">

          <xsl:value-of select="@nodeName"/>

        </a>

        </xsl:if>
      </li>
    </xsl:for-each>
    </ul>

    </xsl:template>
Please Sign in or register to post replies

Write your reply to:

Draft