Copied to clipboard

Flag this post as spam?

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


  • Streety 358 posts 568 karma points
    Feb 01, 2012 @ 16:49
    Streety
    0

    Getting url for <a href from a page picker

    Hello,

    I hope someone can help. I have a pagepicker control on my homepage looking at the node staff. This node has individual bios on staff and from the homepage you can select which ones to show.

    The site runs a xslt that looks up the value of the homepage pagepicker and displays the items selected.

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

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <xsl:variable name="nodeIds" select="umbraco.library:Split($currentPage/staffSelector,',')" />

    <div id="team">
    <ul>
    <xsl:for-each select="$nodeIds/value">

    <li>

    <xsl:variable name="person" select="umbraco.library:GetXmlNodeById(current()/.)"/>

    <a href="#">
    <img alt="{$person/@nodeName}" src="{$person/pictureForFrame}"/>
    </a>
    <br />
    <div class="picframeName">
    <xsl:value-of select="$person/forename" disable-output-escaping="yes"/>

    </div>
    </li>

    </xsl:for-each>
    </ul>
    </div>

    </xsl:template>

    I want to be able to insert within the anchor the url of the page.

    This line gets the reference to the staff nodes:

     <xsl:variable name="person" select="umbraco.library:GetXmlNodeById(current()/.)"/>

    And you can see that I am using the forname and pictureforframe nodes. However I need to link to the url from the anchor and I don't know the syntax.

    Thanks.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 01, 2012 @ 16:57
    Dirk De Grave
    0

    Hi Streety,

    How about

    <a href="umbraco.library:NiceUrl($person/@id)">...</a>

    Hope this helps.

    Regards,

    /Dirk

  • Streety 358 posts 568 karma points
    Feb 01, 2012 @ 17:05
    Streety
    0

    Yes I tried that.

     

    I get a firefox msgbx "Firefox doesn't know how to open this address, because the protocol (umbraco.library) isn't associated with any program."

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 01, 2012 @ 17:09
    Dirk De Grave
    0

    Arrhggghhh, just made a noob mistake, need to wrap that in {}, so

    <ahref="{umbraco.library:NiceUrl($person/@id)}">...</a>

    will work.

     

    Cheers,

    /Dirk

     

  • Streety 358 posts 568 karma points
    Feb 01, 2012 @ 18:27
    Streety
    0

    Bingo!

     

    I don't surpose you care to explain the syntax. What is NiceURL? Does it format the string properly?

  • Streety 358 posts 568 karma points
    Feb 01, 2012 @ 19:40
    Streety
    0

    Bingo!

     

    I don't surpose you care to explain the syntax. What is NiceURL? Does it format the string properly?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 01, 2012 @ 20:12
    Dirk De Grave
    0

    no problem.

    NiceUrl() is a xslt extension method. And without going into too much details, xslt extension methods are static functions declared in a class library, which lives in the umbraco assembly and are globally available in xslt.

    And the syntax for using those methods in xslt is umbraco.library:NiceUrl(). First part (before the semicolon) denotes the xslt namespace, where as the second part is the static function

    umbraco.library is required and refers to one of the namespaces declared in code snippet below and will be included by default when creating an xslt through the umbraco ui.

    <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" xmlns:ucomponents.cms="urn:ucomponents.cms" xmlns:ucomponents.dates="urn:ucomponents.dates" xmlns:ucomponents.io="urn:ucomponents.io" xmlns:ucomponents.media="urn:ucomponents.media" xmlns:ucomponents.members="urn:ucomponents.members" xmlns:ucomponents.nodes="urn:ucomponents.nodes" xmlns:ucomponents.search="urn:ucomponents.search" xmlns:ucomponents.strings="urn:ucomponents.strings" xmlns:ucomponents.urls="urn:ucomponents.urls" xmlns:ucomponents.xml="urn:ucomponents.xml"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ucomponents.cms ucomponents.dates ucomponents.io ucomponents.media ucomponents.members ucomponents.nodes ucomponents.search ucomponents.strings ucomponents.urls ucomponents.xml ">

    If interested in all available umbraco.library xslt extension methods, have a look at this wiki page. (there's more extension libs, you may find them all through the wiki)

     

    Cheers,

    /Dirk

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 01, 2012 @ 20:14
    Dirk De Grave
    1

    Oh, and it does format the string properly... it's the exact same url you may find on each of the document *General Properties* tab and takes into account all *non url* chars which need to be replaced for nice urls (based on settings in umbracoSettings.config)

     

    Cheers,

    /Dirk

  • Streety 358 posts 568 karma points
    Feb 02, 2012 @ 09:46
    Streety
    0

    Thanks Dirk.

Please Sign in or register to post replies

Write your reply to:

Draft