Copied to clipboard

Flag this post as spam?

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


  • jeremy 18 posts 20 karma points
    Mar 26, 2009 @ 21:04
    jeremy
    0

    Redirect to URL

    I know this has been discussed, but for the life of me I cannot figure this one out.

    I'm using Umbraco v4 and I need a content item to redirect to an external URL. How would I go about doing this?

    What I've tried: Neehouse Redirect, umbRedirect and some advice I found in a few threads regarding doc type and xslt. So far nothing has worked and my frustration is building.

    Can someone point me in the right direction or maybe spell it out clearly in this thread?

    Thanks,
    Jeremy

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Mar 26, 2009 @ 21:40
    Peter Dijksterhuis
    0

    Can you post the xslt you tried? Should be fairly easy to setup.

    HTH,
    PeterD

  • jeremy 18 posts 20 karma points
    Mar 26, 2009 @ 22:04
    jeremy
    0

    Sure. It's based on this post.

    In my document type I have two fields:
    External Link; Alias:externalLink; Type: true/False
    Link; Alias: link; Type: Textstring

    XSLT:

    [code]




    [/code]

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Mar 26, 2009 @ 22:27
    Peter Dijksterhuis
    0

    ah, so you have a property in your document and not a documenttype itself
    Change this line:
    [code]

  • jeremy 18 posts 20 karma points
    Mar 26, 2009 @ 22:39
    jeremy
    0

    That worked. Thank you.

  • MartinB 411 posts 512 karma points
    May 20, 2010 @ 19:44
    MartinB
    0

    nice one

    Just what i needed, works great

  • MartinB 411 posts 512 karma points
    May 20, 2010 @ 19:55
    MartinB
    0

    might as well post my xslt as it also contains subpages and the above does not. Just to help others :-)

    <xsl:choose>
    <xsl:when test="./data [@alias='externalLink'] = 1">
    <a href="{./data [@alias='link']}">
    <xsl:value-of select="@nodeName"/>
    </a>
    </xsl:when>

    <xsl:otherwise>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
    <!-- we're under the item - you can do your own styling here -->
    <xsl:attribute name="class">current</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@nodeName"/>
    </a>
    </xsl:otherwise>
    </xsl:choose>
  • MartinB 411 posts 512 karma points
    May 20, 2010 @ 19:56
    MartinB
    0

    doh! Here's the right code lol

    <?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 -->
    <!-- Typically '1' for topnavigtaion and '2' for 2nd level -->
    <!-- Use div elements around this macro combined with css -->
    <!-- for styling the navigation -->
    <xsl:variable name="level" select="1"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul id="menu">
    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']">
    <li>

    <xsl:choose>
    <xsl:when test="./data [@alias='externalLink'] = 1">
    <a href="{./data [@alias='link']}" target="_blank">
    <xsl:value-of select="@nodeName"/>
    </a>
    </xsl:when>

    <xsl:otherwise>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
    <!-- we're under the item - you can do your own styling here -->
    <xsl:attribute name="class">current</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@nodeName"/>
    </a>
    </xsl:otherwise>
    </xsl:choose>

    <!--If a node has children, show them on hover-->
    <xsl:if test="($currentPage/@id and count(current()/node) > 0) or ($currentPage/@parentID = ./@id)">
    <ul id="submenu">
    <xsl:for-each select="current()/node">
    <li>
    <xsl:choose>
    <xsl:when test="./data [@alias='externalLink'] = 1">
    <a href="{./data [@alias='link']}" target="_blank">
    <xsl:value-of select="@nodeName"/>
    </a>
    </xsl:when>

    <xsl:otherwise>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
    <!-- we're under the item - you can do your own styling here -->
    <xsl:attribute name="class">current</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@nodeName"/>
    </a>
    </xsl:otherwise>
    </xsl:choose>
    </li>
    </xsl:for-each>
    </ul>
    </xsl:if>
    </li>
    </xsl:for-each>
    </ul>

    </xsl:template>

    </xsl:stylesheet>

  • mauricio lopez 12 posts 33 karma points
    Jul 05, 2010 @ 15:44
    mauricio lopez
    1

    This code is obsolete with the new 4.5 xml schema

    To access nodes, data is no longer valid, to fix it I did:

     

                <xsl:choose>
                <xsl:when test="externalLink = 1">
                          <a href="{linkext}">
                                           <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>
Please Sign in or register to post replies

Write your reply to:

Draft