Copied to clipboard

Flag this post as spam?

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


  • Jon T 18 posts 38 karma points
    Mar 11, 2011 @ 21:09
    Jon T
    0

    Point a document type to a specific URL

    I need to have a link in my top horizontal navigation that just points to a subdomain without a redirect.   How do I accomplish this?   I don't see anywhere that I can just have the link point directly to a specific URL.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 11, 2011 @ 21:35
    Tom Fulton
    0

    Hi Jon,

    I typically handle this in my navigation menu logic.  IE create a special Document Type called something like "Menu Pointer" with a property to store the redirect URL (textstring or URL Picker works great).  Then in your XSLT test for that doctype and override the href if needed.

    I posted a quick snippet the other day here using the URL picker:http://our.umbraco.org/forum/developers/api-questions/18211-Create-a-document-type-that-just-links-to-another-node

    If you are just using a textstring it would be even easier:

    ...
      <a href="{umbraco.library:NiceUrl(@id)}">
        <xsl:if test="name() = 'MenuPointer'"><xsl:attribute name="href"><xsl:value-of select="yourPropertyAlias"></xsl:attribute></xsl:if>
    ...

    Thanks,
    Tom

  • Jon T 18 posts 38 karma points
    Mar 11, 2011 @ 21:51
    Jon T
    0

    Thank Tom.   I'm new to Umbraco so I'm not really sure what I'm doing.   I did create a MenuPointer document type, then created an XSLT file called "MenuPointer.xslt"--but I'm not quite sure what to do with both sections of code from the link to your other post.   I tried pasting it all into the XSLT file in the <xsl:template match="/"> section that is created from the "Clean" XSLT type.  I am clearly doing something wrong.   How can I fix this?

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 11, 2011 @ 21:59
    Tom Fulton
    0

    You'd want to incorporate this into your horizontal menu code (I assumed XSLT).

    How are you generating your horizontal navigation?  With XSLT?  Try posting the code here and we'll figure it out

  • Jon T 18 posts 38 karma points
    Mar 11, 2011 @ 22:17
    Jon T
    0

    I'm just creating new nodes off of the "content" node and it adds them automatically to the nav bar, regardless of the document type.

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 11, 2011 @ 22:20
    Tom Fulton
    0

    Somehow Umbraco is generating your navigation menu based on the nodes under "content" - usually this is done with an XSLT macro.  Can you check inside your Template and see if you can find a Macro that is generating the navigation?  It would look something like <umbraco:Macro alias="something" runat="server"></umbraco:Macro>

    If you can find the Macro, then check the Developer section and find the matching Alias under the Macros folder.  Then you'll be able to see if it's using an XSLT file or a .NET control.  If it's an XSLT file, you can find the file under the Developer section in the XSLT folder.

  • Jon T 18 posts 38 karma points
    Mar 11, 2011 @ 22:29
    Jon T
    0

           <div id="mainmenu">
               <umbraco:Macro Alias="umbTopNavigation" runat="server"></umbraco:Macro>
           </div>

    And then umbTopNavigation is the following:

     

    <?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"
      exclude-result-prefixes="msxml umbraco.library">


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

        <xsl:param name="currentPage"/>

        <!-- Input the documenttype you want here -->
        <xsl:variable name="level" select="1"/>

        <xsl:template match="/">

        <ul id="topNavigation">
           <li class="home">
             <xsl:if test="$currentPage/@id = $currentPage/ancestor-or-self::* [@level=$level]/@id">
                 <xsl:attribute name="class">home current</xsl:attribute>
             </xsl:if>
             <a href="/">Home</a>
           </li>
          <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
      <li>
         <xsl:if test="@id = $currentPage/@id">
            <xsl:attribute name="class">current</xsl:attribute>
          </xsl:if>
        <a class="navigation" href="{umbraco.library:NiceUrl(@id)}">
          <span><xsl:value-of select="@nodeName"/></span>
        </a>
      </li>
    </xsl:for-each>
    </ul>

        </xsl:template>

    </xsl:stylesheet>

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 11, 2011 @ 22:33
    Tom Fulton
    0

    Ok, so in the for-each loop you'll want to add the additional check for the new Doctype you created, right below the <a> tag, and override the href property:

    <a class="navigation" href="{umbraco.library:NiceUrl(@id)}">
    <xsl:if test="name() = 'MenuPointer'"><xsl:attribute name="href"><xsl:value-of select="yourPropertyAlias"></xsl:attribute></xsl:if>

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

    You'll also want to change "yourPropertyAlias" on that line to whatever you named your property on the MenuPointer doctype.

    Hope this helps :)

     

  • Jon T 18 posts 38 karma points
    Mar 11, 2011 @ 22:47
    Jon T
    0

    Getting closer.   I added it in (I just pasted the <UL> section of my code instead of the whole thing.   But now I'm getting the error "The 'xsl:value-of' start tag on line 40 position 31 does not match the end tag of 'xsl:attribute'. Line 40, position 73. "   Link 40 is the <xsl:atrribute name> row with the "yourPropertyAlias" in it.   What's going wrong here?   And, I do really appreciate this help.

     

     <ul id="topNavigation">
     <li class="home">
      <xsl:if test="$currentPage/@id = $currentPage/ancestor-or-self::* [@level=$level]/@id">
          <xsl:attribute name="class">home current</xsl:attribute>
      </xsl:if>
      <a href="/">Home</a>
     </li>
       <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
       <li>
          <xsl:if test="@id = $currentPage/@id">
      <xsl:attribute name="class">current</xsl:attribute>
           </xsl:if>
         <a class="navigation" href="{umbraco.library:NiceUrl(@id)}">
           <span><xsl:value-of select="@nodeName"/></span>
         </a>
         <a class="navigation" href="{umbraco.library:NiceUrl(@id)}"> 
      <xsl:if test="name() = 'MenuPointer'">
       <xsl:attribute name="href"><xsl:value-of select="yourPropertyAlias"></xsl:attribute>
      </xsl:if> 
      <span><xsl:value-of select="@nodeName"/></span></a>
       </li>
     
       </xsl:for-each>
    </ul>

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 11, 2011 @ 22:49
    Tom Fulton
    0

    Oops, I gave you bad code :)  The <xsl:value-of tag isn't closed properly.  Add a slash at the end to close it:

      <xsl:attribute name="href"><xsl:value-of select="yourPropertyAlias" /></xsl:attribute>
  • Jon T 18 posts 38 karma points
    Mar 11, 2011 @ 23:00
    Jon T
    0

    Ok, I feel like I'm almost there.   That saved.   The navigation works, but I now have no idea where to point that one link to my other URL.   Help?

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 11, 2011 @ 23:04
    Tom Fulton
    0

    You'll need to add a property to the MenuPointer document type you created to store the URL you want to use

    For now you can use a simple textstring property if you like, personally I would use the URL Picker datatype but let's take baby steps :)

    So add a property to the document type called something like "targetUrl" of type "Textstring".  Then goto the document in the Content section and put a URL in the new property and save/publish.

    Then change "yourPropertyAlias" in my code to your property alias ("targetUrl").

    I think that'll do it!

  • Jon T 18 posts 38 karma points
    Mar 11, 2011 @ 23:27
    Jon T
    0

    Ok, I'm getting there, but slightly confused.  That last code I pasted into umbTopNavigation.xslt and then changed the property to point to "targetURL".  I also have a MenuPointer.xslt file that has basically nothing in it.   What should be in that?  Also, my URL is in the content section of my content page.  

  • Jon T 18 posts 38 karma points
    Mar 11, 2011 @ 23:41
    Jon T
    0

    Got it!   Finally figured it out!   Thanks so much for your help!!   Wow.

Please Sign in or register to post replies

Write your reply to:

Draft