We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3688
    • 43 Posts
    Hi,

    I want to create an anchor-link ("go to top"). That actually does not work, for something like
    <a href="#top">

    produces a link to http://www.homepage.com/#top (but not ..homepage.com/mydocument.html#top).

    I created an emergency solution with
    href="[[+site_url]][[*alias]].html#top


    This actually works (because I have friendly URLs on), but as you can imagine this is far from ideal.

    Isn't there any way just to pull the URL of the current page I am on?

    Thanks for your help in advance!

    This question has been answered by comp_nerd26. See the first response.

    • discuss.answer
      • 47401
      • 295 Posts
      try this:
      [[~[[*id]]]]

      append #top at the end
        • 3688
        • 43 Posts
        comp_nerd26 - this is exactly what I was looking for. Works!

        Thanks a lot!

        (my case solved)
          • 47401
          • 295 Posts
          no problem, happy to help smiley
            • 36516
            • 179 Posts
            It might also be worth mentioning that the root cause of your problem is actually the <base> tag in your HTML, I suspect.

            I've had the same trouble recently when trying to use named anchors and such for auto-scrolling. I've had to use a bit of a javascript to work around the issue in some specific cases, as opposed to considing removing <base href="[[+site_url]]"/> from the <head>. It's that which causes URLs like "#top" to be automatically prefixed with your site URL.

            Tweaking your URLs to account for <base> is one approach, but should it turn out you don't really need <base> you'll find it a little easier to remove it. Depends on whether you want to be able to create # links regularly, and easily, or if you only need it for a single item, like a permanent menu item.
              • 3749
              • 24,544 Posts
              And if you have multiple front-end contexts, make it:
              <base href="[[!+site_url]]"/> 
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting