We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    This is an auto-generated support/comment thread for TemplateSwitcher.

    Use this forum to post any comments about this addition or any questions you have regarding its use.

    Brief Description:
    Switch to a specified template when a page is requested
      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
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Version 1.2 has been submitted to the Repository. This automates the selection of one-page-only or cookie-based site-wide template switching. Update the code in the plugin, and add the value to the Configuration tab. Now, just select "Yes" or "No" in the Configuration tab.
        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
        • 15987
        • 786 Posts
        Susan,
        I think I may have found a problem with this plugin. When a user changes the template and the cookie is set to remember the selection, if the user visits a page that has caching turned on and the page is not yet cached, the changed template will get stored in cache and not the default template you may have intended.

        I’m not sure there is a way to fix this in the code, but if you visit all of your pages with the default template first they will get cached the expected way.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Yes, I’ve noticed problems with caching while using this.
            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
            • 28584
            • 27 Posts
            Quote from: sottwell at Sep 19, 2006, 12:23 PM

            Yes, I’ve noticed problems with caching while using this.
            I must say cache issue aside this is a great idea for a plugin.
            I’m looking at offering good accessibility options and even better than just switching the CSS is having control of the order the source is built, templates and this can make that task easier which should hopefuly make accessibility minded content management sites a much easier task.

            thanks susan!
              • 6726
              • 7,075 Posts
              I have trouble understanding the behavior of this plugin, at least for my particular purpose, which is to remember if a visitor doesn’t want to see the flash intro again (this is continued from Use the Template Switcher to skip flash intro for return visitors and Using AJAX to load a flash intro : a breeze with LITBox !)

              Per Kudolink’s advice, I have tried to use the TemplateSwitcher to do just that but I fail to achieve this, at least if I want the plugin to work only on the homepage. I have taken into account the cache issue and uncached my homepage. When I set the plugin to work sitewide, the cookie is set and the proper template is selected. Also, if I properly add the donotswitch to other page’s content, everything works fine.

              But I’d rather not rely on editors adding the donotswitch themselves to the content field every time a new document is created... (While I am here : is it possible to define a default value for content like we do for TVs ?), and I’d rather not have the cookie set sitewide.

              My question is, why doesn’t it work when the plugin is not set sitewide ? Or do I have to uncache the whole website for it to work that way ?

              You can see the website I am working on there. The top right link in the Flash window is the skip intro link (http://ns20999.ovh.net/~sworld/?template=accueil). I have two templates, one for the homepage with flash is "intro" and the one with the homepage without flash is "accueil". Right now I have switched the sitewide setting to "no".

              Any thought or advice (maybe another method should be used in my case...) ?
              Thanks !

                .: COO - Commerce Guys - Community Driven Innovation :.


                MODx est l'outil id
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                I haven’t really been able to figure out how this is suitable for your purposes. I would use a snippet to display the flash if the referrer is not the same site; this way it would only show on first access to the site’s home page.
                  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
                  • 6726
                  • 7,075 Posts
                  Thanks Susan.

                  I have been thinking, could I just replace

                  if(!strstr($modx->documentContent, "donotswitch")) { // this page is not switchable


                  by

                  if(strpos($template, 'donotswitch') === false) {


                  Forgive my php illiteracy, but the intent is to have the plugin check wether the donotswitch is in the template rather than content, which would allow me to just add it in the templates and then solve my problem.

                  Would that work ?
                    .: COO - Commerce Guys - Community Driven Innovation :.


                    MODx est l'outil id
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    There was a reason why that didn’t work. I don’t remember why, now.
                      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
                      • 6726
                      • 7,075 Posts
                      OK thanks for the quick reply, I’ll look in another direction then...
                        .: COO - Commerce Guys - Community Driven Innovation :.


                        MODx est l'outil id