Copied to clipboard

Flag this post as spam?

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


  • Tom Cowling 144 posts 343 karma points
    Jan 18, 2011 @ 13:36
    Tom Cowling
    0

    Current url to variable problem (should be simple!)

    Hi,

    I'm sure this should be REALLY easy, but for some reason it just isn't working. I've scoured the forums and can't seem to find an answer to this. Basically all I want to do is pass the current page's url to a variable so I can use it later on.I can get it to print out the site's domain if I take out the following line

    <xsl:value-of select="umbraco.library:NiceUrl(@id)" />

     

    but as soon as I try to get the current node, it throws a wobbly and tells me there is a problem with my xslt (System.OverflowException: Value was either too large or too small for an Int32.)

    Below is my code:

    <?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="pageURL">
        <xsl:text>http://</xsl:text>
      <xsl:value-of select="umbraco.library:RequestServerVariables('HTTP_HOST')" /><xsl:value-of select="umbraco.library:RequestServerVariables('HTTP_HOST')" /><xsl:value-of select="umbraco.library:NiceUrl(@id)" />
      </xsl:variable>
    <xsl:template match="/">
    <!-- start writing XSLT -->
     
      <p>Page url is:<br /><xsl:value-of select="$pageURL"/></p>

    </xsl:template>

    </xsl:stylesheet>

    Any light that can be shed on this would be much appreciated!

     

    Thanks a lot,

    Tom

  • Tom Cowling 144 posts 343 karma points
    Jan 18, 2011 @ 13:41
    Tom Cowling
    0

    Sorry this is the code used:

    <?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="pageURL">
      <xsl:text>http://</xsl:text>
      <xsl:value-of select="umbraco.library:RequestServerVariables('HTTP_HOST')" /><xsl:value-of select="umbraco.library:NiceUrl(@id)" />
      </xsl:variable>
    <xsl:template match="/">
    <!-- start writing XSLT -->
     
      <p>Page url is:<br /><xsl:value-of select="$pageURL"/></p>

    </xsl:template>

    </xsl:stylesheet>

     

    For some reason, the forum won't let me edit the original...

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jan 18, 2011 @ 13:45
    Dirk De Grave
    0

    Don't you have to use $currentPage/@id instead of only @id?

     

    Cheers,

    /Dirk

  • Tom Cowling 144 posts 343 karma points
    Jan 18, 2011 @ 13:46
    Tom Cowling
    0

    Spot on!

    Nice one. :D

  • Adam 7 posts 27 karma points
    Jan 19, 2011 @ 07:21
    Adam
    0

    Hi,

    I'd like to take this one step further and insert the value of the url into an alias I've got called "myURL".

    I'm working on a "Send to a friend" form using Doc2Form and loading it within an iframe, so I need to feed the form the URL via the myURL alias.

    This should be simple, but it's stumping me for now.

    Any help is appreciated.

    Cheers

    Adam

  • Tom Cowling 144 posts 343 karma points
    Jan 19, 2011 @ 10:35
    Tom Cowling
    0

    Funnily enough, that's exactly what I wanted it for! :)

     

    Code below:

    <?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="pageURL">
        <xsl:text>http://</xsl:text>
        <xsl:value-of select="umbraco.library:RequestServerVariables('HTTP_HOST')" />
        <xsl:value-of select="umbraco.library:NiceUrl($currentPage/@id )" />
      </xsl:variable>
        
      <xsl:variable name="pageTitle">
        <xsl:value-of select="$currentPage/data[@alias='Heading']"/>
      </xsl:variable>
    <xsl:template match="/">
    <!-- start writing XSLT -->


    <p><strong>Bookmark &amp; Share this article with:</strong></p>

    <a title="Share this article on Twitter" target="_blank" href="http://twitter.com/home?status={$pageURL}">Twitter</a>

    </xsl:template>
    </xsl:stylesheet>

     

    Good luck!

     

    Tom

    
    
                
  • Adam 7 posts 27 karma points
    Jan 31, 2011 @ 00:16
    Adam
    0

    Hi Tom,

    Thanks heaps for your help with my problem, and sorry it's taken me a while to get back about this.

    I can see how to store a value into a variable, but not how to send that value to a field (or alias) in another page via Umbraco. I'm no .net/c# wiz so perhaps I'm missing something obvious?

    In the end I leveraged on jQuery for the final solution. The user needs javaScript to view videos anyway, so to send the current video to a friend, I copied the url to the iframe form that Doc2Form generates for the user to send off, and it works well.

    Cheers

    Adam

     

    Code below if you're curious.

    $("#email-friend").click(function () {
        //Grab the current Page URL
        var pageURL = document.location.href;
    
        //Locate the field (#ctl00_ctl00_ContentPlaceHolderDefault_Doc2Form_1_myURL) in the iframe (#email-friend-fr) to store the Page URL
        var sendURL = $("#email-friend-fr").contents().find("#ctl00_ctl00_ContentPlaceHolderDefault_Doc2Form_1_myURL");
    
        //Inject the Page URL into the hidden URL field inside the iframe form.
        $(sendURL).val(pageURL);
    
        return false;
    });

Please Sign in or register to post replies

Write your reply to:

Draft