Copied to clipboard

Flag this post as spam?

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


  • J 447 posts 864 karma points
    Apr 03, 2019 @ 12:08
    J
    0

    Get current page URL

    I have an XSLT and wonder how i retrieve the URL for the page visited (that is being viewed)?

    Example:

    I visit https://www.site.com/library then the URL i want returned is https://www.site.com/library

    If i visit https://www.site.com/library?g="drama" then the URL would be https://www.site.com/library?g="drama"

  • Alex Skrypnyk 6167 posts 24147 karma points MVP 8x admin c-trib
    Apr 03, 2019 @ 20:49
    Alex Skrypnyk
    1

    Hi J

    Probably everything what you need is

    Request.Url.AbsoluteUri
    
  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Apr 04, 2019 @ 09:12
    Tim
    100

    If the XSLT is being rendered as an Umbraco macro, the following should do the trick:

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

    The $currentPage variable inside umbraco XSLT macros contains the entire node for the current page, so you can access the properties etc for the current age as well if you need them!

    If you want to include the query string as well, you may need to write your own XSLT extension to get it, as the built in umbraco library only gets individual query string items by key IIRC. If you have uComponents installed, that has an extension method already, called ucomponents.request:QueryString().

Please Sign in or register to post replies

Write your reply to:

Draft