• [Plugin] AnchorsAway#

  • opengeek Reply #1, 4 years, 7 months ago

    Reply
    A common problem when developing content in MODx is with anchor tags not working for the current page, due to the base tag required to properly maintain relative paths. To solve this, you can use the following very simple plugin (check the OnWebPagePrerender event):
    <?php
    $e= & $modx->Event;
    switch ($e->name) {
        case "OnWebPagePrerender" :
            $modx->documentOutput= str_replace('href="#', 'href="' . $modx->makeUrl($modx->documentIdentifier) . '#', $modx->documentOutput);
            break;
    }
    ?>


    NOTE: Be sure not to include the <?php ?> tags in the plugin editor...
    This should work in most situations, but let me know what you think or if you encounter any problems with it. I'll add it to the repository soon.


  • Uncle68 Reply #2, 4 years, 7 months ago

    Reply
    Very nice! Two hours ago I was sitting wondering why I couldn't get anchors to work. And now this! Great!
    Works fine!


  • sirlancelot Reply #3, 4 years, 7 months ago

    Reply
    Brilliant!

    Clever name too


  • heliotrope Reply #4, 4 years, 6 months ago

    Reply
    Hi,

    This one will work without changing the start id page in the plugin code


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


    :-)


  • rthrash Reply #5, 4 years, 6 months ago

    Reply
    Nice tweak heliotrope ... care to put this sucker in the Resources library?


  • davidm Reply #6, 4 years, 6 months ago

    Reply
    Indeed that would be cool, I missed it though I browse the forums daily, cool plugin !


  • marco garcia Reply #7, 3 years, 11 months ago

    Reply
    Is this plugin still working? I was noticing the anchor issue and found this thread.

    I created a plugin based on : Quote from: heliotrope at Jul 19, 2007, 08:00 AM
    Hi,

    This one will work without changing the start id page in the plugin code


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


    :-)

    and also made sure that OnWebPagePrerender was checked off on System events. All my anchors are currently sending me to the homepage.


  • dev_cw Reply #8, 3 years, 11 months ago

    Reply
    I used this plugin on my last project on 0.9.6.1 and it worked fine. I think I used the original release from the repository, I recommend using that one.


  • L_Harmonica Reply #9, 3 years, 11 months ago

    Reply
    I have the same problem than marco garcia...

    Any idea ?
    [edit] Uhuhuh, fixed it by myself : try without the <?php ... ?> and it's cool. Sorry...


  • dollyp Reply #10, 3 years, 10 months ago

    Reply
    Have used all variants of the plugin siggested on this page and still all the anchors are going back to the homepage. I'm using version 0.9.5 and cannot upgrade yet (compatibility issues). any ideas fellas?