New Community Forums are coming. Watch this space for news.
Subscribe: RSS
  • Does anybody know how to make links in Revo work referring to anchors on the same page like this <a href="#anchor">Anchor</a>?

    In our MODx-Revolution it works only by adding <a href="[[~page-id]]]#anchor">Anchor</a>

    Our goal is to import a webpage including about 1.000 anchors with the syntax <a href="#anchor">. Because of this it would be great if we could keep this syntax.

    Does anybody know how to make this work?

    Gerdi smiley
    • <a href="[[~[[*id]]]]#anchor">anchor</a>


      oops sorry should have read your question better.

      So you would like a plugin that converts "#anchor" to the proper url? - sorry I’m unaware of one for revo yet.

      Wouldn’t a quick search and replace be sufficient for an import?
        |
      • Thanks for your answer. But I think this wouldn´t be our preferred solution. We would like to avoid to change every link on this new webpage.

        In Evo there is a package to solve this problem I have seen here: http://modxcms.com/extras/package/41

        Is there a similar solution for Revo, too?

        Gerdi smiley
        • We also have this problem. To be honest, I don’t know why a package is necessary for this. Why does MODX work this way? If I insert an anchor on a page, I would expect that anchor to not be attached by default to the home page. This is annoying and should be a bug fix, not new functionality or a package.
          • I got it to work by using the code of plugin Base URL Same-Page-Link Fix. I followed installation instructions of this plugin and only thing what I changed was replacing this line
            $source = &$modx->documentOutput;

            with this
            $source = &$modx->resource->_output;

              • Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
              • Quote from: sottwell at Oct 06, 2011, 01:25 AM
                http://modx.com/extras/package/baseurlsamepagelinkfix

                I could not manage to get this work.

                My code is:
                if($modx->resource->get('id') !=$modx->config['site_start']) //not on Startpage
                {
                   $newOutput=str_replace('href="#', 'href="' .$modx->makeUrl($modx->resource->get('id')) .'#', $modx->resource->_output);
                   $newOutput=str_replace('/#', '#', $newOutput); //if the page is a folder!!!
                   $modx->resource->_output = $newOutput;
                }
                


                derived from:
                https://docs.modx.com/revolution/2.x/making-sites-with-modx/structuring-your-site/resources/named-anchor [ed. note: androme16 last edited this post 2 months, 1 week ago.]
                • See if this makes a difference:

                  $modx->makeUrl($modx->resource->get('id'), "", "", "full");


                  Is your plugin attached to OnWebPagePrerender?

                  If that doesn't work, you can always put this at the top of the page in your template:

                  <a name="top"></a>


                  Then do this in your plugin:

                  if($modx->resource->get('id') !=$modx->config['site_start']) //not on Startpage
                  {
                     $newOutput=str_replace('href="#', 'href="' .$modx->makeUrl($modx->resource->get('id'), "", "", "full") .'#top', $modx->resource->_output);
                     $newOutput=str_replace('/#', '#top', $newOutput); //if the page is a folder!!!
                     $modx->resource->_output = $newOutput;
                  }
                    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
                  • Quote from: BobRay at Dec 04, 2018, 06:13 AM
                    See if this makes a difference:...
                    Thanks BobRay for your quick reply.

                    Sorry,
                    there was 1 word to much in my posting above. Now I emended it to "I could manage to get this work."
                    So I hope your code and my code can help others.

                    The important thing was to make it work for folders also:
                    $newOutput=str_replace('/#', '#', $newOutput); //if the page is a folder!!!
                    


                    Seems to be OK:
                    $modx->makeUrl($modx->resource->get('id'))
                    
                    • Looks good.
                        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