We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28454
    • 13 Posts
    Hi

    Anyone know how easy it is to show a template based on what backlink the viewer came from?

    Cheers
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Would need a template changing plugin. See the "template switcher" plugin; you could modify that code easily enough.
        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
        • 24530
        • 100 Posts
        Is it possible to put the templates in two Snippets and use the "swapChunkonReferer"-snippet in the (real) template to choose which chunk to display?
          my newest webpage [url=http://gitarren.zucali.at]Meisterwerkstatt f
          • 27376
          • 576 Posts
          Quote from: raum at Mar 13, 2007, 07:50 AM

          Is it possible to put the templates in two Snippets and use the "swapChunkonReferer"-snippet in the (real) template to choose which chunk to display?
          You’d need to call the snippet [!uncached!], but yes it would work.
            • 28454
            • 13 Posts
            "Would need a template changing plugin. See the "template switcher" plugin; you could modify that code easily enough."

            Any ides on how to modify the teplate pugin to acheive this?
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Instead of selecting the template depending on the $_GET value, have it depend on the HTTP_REFERER (at least I presume that’s what you mean by a "backlink"). Use a switch statement if there are certain templates you want for certain "referers", with the default for all the others.
                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
                • 24530
                • 100 Posts
                I did a really, really simple snippet to determine if the referer is from outside. It gives back "false" or "true".
                (I use these values to set javascript values)

                It is really the easiest way to do it - there are no snippet variables set or so - but it could give a start ... (if it is not too late anyway ...)

                <?php
                if (strpos($_SERVER['HTTP_REFERER'], $_SERVER['SERVER_NAME'])) {
                echo 'false';
                } else {
                echo 'true';
                }
                ?>
                  my newest webpage [url=http://gitarren.zucali.at]Meisterwerkstatt f
                  • 28454
                  • 13 Posts
                  I am still a little confused a how to acheive this as i am not the greatest when it comes to PHP.

                  Also! as i understand it, using http_referer is a little unstable as not all browsers will send this information.

                  The reason i want to do this is because i have someone who wants to use the content of my site with but with his template and contact details, and i dont want to duplicate the content!!
                    • 32319
                    • 129 Posts
                    you could always put your content in chunks to resolve that issue...

                    The problem from sniffing for referrer is that if someone comes to the page from another place, say a bookmark later or they click away then go back is that they are likely to get your template again. You would have to set a cookie based on their first access or something along those lines. Gets kinda messy. I would just put your content in chunks...

                      "Regret for the things we did can be tempered by time; it is regret for the things we did not do that is inconsolable."
                      -- Sydney Harris