We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11054
    • 59 Posts
    I’ve read several posts about using Anchors Away to get anchors on the same page to work properly but I’m not getting the right result.

    The anchors in my pages are still generating like <a href="[~id~]#anchor">link</a>.

    Moreover, when I click on that anchor, the page refreshes with the anchor section at the very top of the page. You aren’t able to scroll above the anchor freely. It’s as if MODx regenerated the page and cropped the top of the page off.

    I’m sure I’m missing something here. Any thoughts?
      • 11054
      • 59 Posts
      Anyone??!! :’(

      Here’s the plugin code added:

      $e= & $modx->Event;
      switch ($e->name) {
      case "OnWebPagePrerender" :
      if($modx->documentIdentifier != $modx->config[’site_start’]) {
      $modx->documentOutput= str_replace(’href="#’, ’href="’ . $_SERVER[’REQUEST_URI’] . ’#’, $modx->documentOutput);
      }
      break;
      }

      Called the Plugin AnchorsAway.

      Clicked OnWebPagePrerender.

      ANYONE!
        • 22303 MODX Staff
        • 10,725 Posts
        This works great for a lot of people. But it’s hard to say what you are experiencing without more details unfortunately.
        Quote from: golds30 at Jan 27, 2010, 11:56 PM

        The anchors in my pages are still generating like <a href="[~id~]#anchor">link</a>.
        The generated output includes [~id~] ? Is this in a Ditto template by chance?

        Quote from: golds30 at Jan 27, 2010, 11:56 PM

        Moreover, when I click on that anchor, the page refreshes with the anchor section at the very top of the page. You aren’t able to scroll above the anchor freely. It’s as if MODx regenerated the page and cropped the top of the page off.
        I don’t understand what this has to do with AnchorsAway or even where to begin diagnosing this behavior. It’s got to be something in your markup or a particular add-on you are using on the page( s ).
          • 26931
          • 2,314 Posts
          not sure what you’re trying to achieve too, but this could be interesting for you (Self Reference Extended):
          http://setpro.pl/software/self-reference
            • 11054
            • 59 Posts
            Thanks to both of you for the response!

            @OpenGeek: The link below is being generated by WayFinder. Not sure if this is a bad practice with WayFinder, but in the document tree I’ve created three weblinks with the link being the anchors in the parent page. These anchors appear in the menu as children of that parent page. So, it looks like this:

            WayFinder Menu:
            <ul class="parent">
            <li><a href="[~1~]">Parent</a>
            
            <ul class="children_anchors">
            <li><a href="[~1~]#Anchor1">Child Anchor</a></li>
            <li><a href="[~1~]#Anchor2">Child Anchor 2</a></li>
            <li><a href="[~1~]#Anchor3">Child Anchor 3</a></li>
            </ul>
            
            </li>
            
            <li><a href="[~5~]">Other Page</a></li>
            <li><a href="[~6~]">Other Page2</a></li>
            </ul>


            Content of Active Parent Page:
            <a name="Child Anchor"><h2>Section 1</h2>
            <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
            <a name="Child Anchor 2"><h2>Section 2</h2>
            <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
            
            <a name="Child Anchor 3"><h2>Section 3</h2>
            <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>


            The anchors in the menu do work and do take you to that content on the parent page. The problem is that when you click on the anchor links in the menu, the page refreshes with the anchor content as the top of the page, and you can’t scroll back to the top.

            For example, if I clicked on the "Child Anchor 3" in the menu, the page would refresh and Child Anchor 3 would be the very top of the page. I couldn’t scroll back up to Child Anchor, nor Child Anchor 2, nor anything that was above that. The entire top of the page is gone.

            The more I’ve messed around with this seems like it has more to do with the way that the page is loading than the plug-in. Is this a page caching issue?

            @sharkbait: Thanks for the suggestion! I’m still new to ModX, but can that snippet solve the issue I described above. Seems more to deal with pagination problems. I know I wasn’t clear about it before, but ditto isn’t being used, and there is no pagination involved.

            Thoughts?
              • 33337
              • 3,975 Posts
              Can we see it online ourselves? That would help understanding the issue. smiley
                Zaigham R - MODX Professional | Skype | Email | Twitter

                Digging the interwebs for #MODX gems and bringing it to you. modx.link
                • 11054
                • 59 Posts
                Hey guys! Thanks again for taking a look at this.

                Here’s the link: http://gator1092.hostgator.com/~puccini/index.php?id=4
                  • 26931
                  • 2,314 Posts
                  does this work?
                  <ul class="children_anchors">
                  <li><a href="#Anchor1">Child Anchor</a></li>
                  <li><a href="#Anchor2">Child Anchor 2</a></li>
                  <li><a href="#Anchor3">Child Anchor 3</a></li>
                  </ul>


                  you could try a custom wayfinder rowTpl:
                  <li class="level2 [+wf.classnames+]"><a href="#[+wf.title+]" title="[+wf.title+]" [+wf.attributes+]>[+wf.linktext+]</a></li>
                  call it e.g. "customrow" and add it to your wayfinder call &rowTpl=`customrow`

                  AnchorsAway plugin should be activated
                    • 11054
                    • 59 Posts
                    I’m not sure that is the issue. I actually have created links to the anchors in the page content by hand like you’re suggesting <a href="#anchor">Link</a> and I get a similar result in the way the page loads (described above).

                    Very strange....

                      • 26931
                      • 2,314 Posts
                      okay, use id instead of name and take care that <?php ?> is not included in the AnchorsAway plugin

                      e.g. id="blanc" etc

                      *edit: but use it in combination with the wayfinder rowTpl i posted above