We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38705
    • 101 Posts
    Hi, on a site where i installed discuss i have al little problem with an anchor-link.

    On the top of my template (wrapper.tpl) i have a little tab that slides out a bit and users can click buttons as "edit profile" and such.
    The sliding action is a jQuery function.
    I created a plugin that fires on OnWebPagePreRender as suggested in the rtfm http://rtfm.modx.com/display/revolution20/Named+Anchor
    if($modx->resource->get('id') !=$modx->config['site_start']) {  
    	$modx->resource->_output =str_replace('href="#','href="' .$modx->makeUrl($modx->resource->get('id')) .'#',$modx->resource->_output);
    	}


    Works like a charm, except when users are at the forums, then the link on the slider is the top-page of discuss (the actual resource), in my case /forums.
    So if i am at /forums/thread/443/parking-place the link on the tab (to let it slide out) points to /forums, which is another page...

    Does anyone know how to call the correct url?
    So i get the url like this: /forums/thread/443/parking-place instead of only /forums?

    tried a snippet that echoes $_SERVER['PHP_SELF'], but that didn't work...

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

      Addict since 2012....
    • I think you would want to update your $modx->makeURL to include the scheme: http://rtfm.modx.com/display/revolution20/modX.makeUrl

      if($modx->resource->get('id') !=$modx->config['site_start']) {  
          $modx->resource->_output =str_replace('href="#','href="' .$modx->makeUrl($modx->resource->get('id'),'','','full') .'#',$modx->resource->_output);
          }


      Update: on second thought, I bet that may not do it … hmmm.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 38705
        • 101 Posts
        Solved it, at this moment without problems, with this code:

        <?php
        if($modx->resource->get('id') !=$modx->config['site_start']) {  
        	$modx->resource->_output =str_replace('href="#','href="' .$_SERVER['REQUEST_URI'].'#',$modx->resource->_output);
        	}


        I don't know if i run into trouble this way?

        Cheers,
        Michiel
          Addict since 2012....
        • discuss.answer
          Using request_uri would probably be easiest/best.

          There's also a Discuss-generated url (I think it's [[+discuss.config.url]] or [[+discuss.url]]) that should contain the canonical url to whatever you are viewing.
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.