Topic: [Plugin] AnchorsAway  (Read 10652 times)

Pages: [1] 2  All   Go Down

#1: 14-Jun-2007, 12:37 PM

Foundation

OpenGeek
MODx Co-Founder
Posts: 7,728

damn accurate caricatures...

WWW
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):
Code:
<?php
$e
= & $modx->Event;
switch (
$e->name) {
    case 
"OnWebPagePrerender" :
        
$modx->documentOutputstr_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.
« Last Edit: 14-Jun-2007, 12:46 PM by OpenGeek »

#2: 14-Jun-2007, 02:22 PM

Moderators

Uncle68
Posts: 304

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

Works fine! Smiley
« Last Edit: 14-Jun-2007, 02:30 PM by Uncle68 »

#3: 14-Jun-2007, 06:42 PM

Coding Team

sirlancelot
Posts: 576

PHP, XML, XSL Supporter

WWW
Brilliant!

Clever name too Smiley

#4: 18-Jul-2007, 02:51 PM


maff
Posts: 49

WWW
Thank you, very nice Smiley

I only had one problem: when I use anchors on the start page (http://www.example.com/#top) it adds the alias name or the call to the index.php file to the link (http://www.example.com/index.html#top or http://www.example.com/index.php?id=1#top) which results in page reloading. So I added one line to check if I'm on the start page (change the value to your start page ID).

Code:
<?php
$e
= & $modx->Event;
switch (
$e->name) {
    case 
"OnWebPagePrerender" :
        if(
$modx->documentIdentifier != 1) {
            
$modx->documentOutputstr_replace('href="#''href="' $modx->makeUrl($modx->documentIdentifier) . '#'$modx->documentOutput);
        }
        break;
}
?>


maFF
Location: Austria | PhpThumb Integration | mafflog

#5: 19-Jul-2007, 08:00 AM

Coding Team
heliotrope
Posts: 2,545

WWW
Hi,

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


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


:-)
« Last Edit: 19-Jul-2007, 08:05 AM by heliotrope »

#6: 19-Jul-2007, 08:31 AM

Foundation

rthrash
Posts: 11,575

WWW
Nice tweak heliotrope ... care to put this sucker in the Resources library?
MODx is a content management framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Please help us help you when asking for assistance and read the wiki. Searching the forums from the top level helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.

#7: 19-Jul-2007, 11:22 AM

Marketing & Design Team

davidm
MODx evangelist
Posts: 7,076

The best way to predict the future is to invent it

WWW
Indeed that would be cool, I missed it though I browse the forums daily, cool plugin Smiley !
.: nodeo.net : Pour un web libre, moderne et ouvert ! :: david-molliere.net : Suivez en "live" mes expérimentations et billets sur les CMS et autres applications web :.

*** Forums modxcms.fr Participez à l'élaboration du site MODx francophone ! ***

! Nouveau !  En live, ne manquez pas les news de modxcms.fr sur Twitter   ! Nouveau !

MODx est l'outil idéal pour les developpeurs et webdesigners qui cherchent un framework de gestion de contenu hautement flexible et performant, tout en étant simple d'accès pour les utilisateurs finaux.

Config : Apache 2.2.8 - MySQL 5.0.67 - PHP 5.2.8 | Debian 4.0 (Etch)

Réalisations sous MODx : | pargade-notaires.fr | soleil.info | gican.asso.fr | michelez-notaires.com | amadom.gerondicap.com | jocelyne-violet.net

#8: 20-Jul-2007, 10:12 AM


maff
Posts: 49

WWW
Oh, nice idea, I did it quite quickly Wink Thanks!
Location: Austria | PhpThumb Integration | mafflog

#9: 30-Jul-2007, 06:05 AM


maff
Posts: 49

WWW
hmm, I got one problem: I have a site which uses GET Parameters to set the subject of a contactform (e.g. http://www.example.com/contact/?subject=test). Using the Plugin, clicking on an anchor results in reloading the page without GET Parameters. So I changed it to use $_SERVER['REQUEST_URI'] and it seems to work. Any comments why not to use this version?

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

maFF
« Last Edit: 10-Nov-2007, 11:10 AM by maFF »
Location: Austria | PhpThumb Integration | mafflog

#10: 17-Feb-2008, 01:37 AM

marco garcia
Posts: 34

MODx is awesome !!

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

I created a plugin based on :
Hi,

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


Code:
<?php
$e
= & $modx->Event;
switch (
$e->name) {
    case 
"OnWebPagePrerender" :
        if(
$modx->documentIdentifier != $modx->config['site_start']) {
            
$modx->documentOutputstr_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.

#11: 17-Feb-2008, 06:42 AM

Testers

dev_cw
Posts: 4,218

WWW
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.
Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

Something is happening here, but you don't know what it is.
Do you, Mr. Jones?  -  [bob dylan]

#12: 29-Feb-2008, 07:42 AM

L_Harmonica
Posts: 21

I have the same problem than marco garcia...

Any idea ?  Roll Eyes

[edit] Uhuhuh, fixed it by myself : try without the <?php ... ?> and it's cool. Sorry...  Grin
« Last Edit: 29-Feb-2008, 07:46 AM by L_Harmonica »

#13: 3-Apr-2008, 04:33 AM

dollyp
Posts: 8

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?

#14: 8-Apr-2008, 07:42 PM

Vait
Posts: 197

WWW
wont it be easier just to put [~[*id~]~] tag in front of the link?
Pure MODx sites
Viriko.ru & Viriko.com - Multilingual and running on 1 MODx

#15: 9-Apr-2008, 07:45 AM

Foundation

rthrash
Posts: 11,575

WWW
I'm using version 0.9.5 and cannot upgrade yet (compatibility issues).

What issues?
MODx is a content management framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Please help us help you when asking for assistance and read the wiki. Searching the forums from the top level helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.

#16: 9-Apr-2008, 11:28 AM

Foundation

OpenGeek
MODx Co-Founder
Posts: 7,728

damn accurate caricatures...

WWW
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?
Lot's of possible issues here dollyp.  Are you rendering the pages directly or summarizing the content containing the anchors via Ditto?  If directly, did you make sure and clear the entire site cache after enabling the plugin?  How are your anchor href attributes formatted?  We'll be glad to help, but try and provide a little more information if you can...

#17: 10-Apr-2008, 06:44 AM

dollyp
Posts: 8

Thanks Vait. That did the trick.

#18: 10-Apr-2008, 07:02 AM

Vait
Posts: 197

WWW
btw I missed a * in the prev post
instead of [~[*id]~] it should be [~[*id*]~]
Pure MODx sites
Viriko.ru & Viriko.com - Multilingual and running on 1 MODx

#19: 18-Dec-2008, 08:25 AM

designetic
Posts: 153

where do I actually place this code?  Huh

#20: 17-Jun-2009, 09:23 AM


Pete
Posts: 145

Berating the internet one line of code at a time

WWW
This is a very useful bit of code.

Silly question - why is this not default behaviour? Am I being unimaginitive in not being able to think of a scenario where this plugin wouldn't be useful?
Notanotherdotcom Ltd

Web | Print | Marketing
Pages: [1] 2  All   Go Up
0 Members and 1 Guest are viewing this topic.