We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37550 ☆ A M B ☆
    • 711 Posts
    Just been using this plugin it seems pretty good, has anyone else come up with a modifed version ideally I’m after a template switcher which is added to partiular pages and not everything.

    For example I have the following pages (front end):

    Choose template (stores details in mySQL)
    Add edit / pages i.e. home | about us | the venue

    Users can edit these pages and the results are stored in a seperate mySQL table.

    Now comes the tricky part Ive created 3 pages in MODx manager which loads the database content for the relevant page this works fine and can be seen with the pages i created i.e user-home.html | user-about-us.html | user-the-venue.html these load with the default site template however I would like these pages to switch the template depending on the users choice in the database.

    I think I could modify the templateswitcher to query the webuser table and get the relevant template ID and change on the fly without adding to the URL but i guess my question is how can i restrict OnLoadWebDocument to just the user pages?

    Hope it all makes sense.

    Aaron
      http://www.onesmarthost.co.uk
      UK MODX Hosting with love.
      • 37550 ☆ A M B ☆
      • 711 Posts
      Just managed to figure it out smiley

      For anyone want to change a page based on the webusers pre selected selction you can do this:

      Requirements
      1) You must already be storing the users template selection in a database for myself i stored this template name in a custom table called modx_web_user_details and the field was called template_name

      2) For my site it looks up the logged in webuser and pulls the ID to get the query.


      TemplateSwitch Plugin


      $id = $modx->documentIdentifier;
      $tv = $modx->getTemplateVarOutput(array("TemplateSwitch"), $id);
      $templateswitch = $tv["TemplateSwitch"];

      if ($templateswitch == "yes") {
      $usernameid = $modx->getLoginUserID();
      $table = $modx->getFullTableName("web_user_details");
      $result = $modx->db->select("template_name",$table,"webuser = ’" .$usernameid ."’");
      if($modx->db->getRecordCount($result) == 1) {
      $row = $modx->db->getRow($result);
      $template_name = $row[’template_name’];
      }

      if ($template_name != "") {
      $table = $modx->getFullTableName("site_templates");
      $result = $modx->db->select("id, content",$table,"templatename = ’" .$template_name ."’");
      if($modx->db->getRecordCount($result) == 1) {
      $row = $modx->db->getRow($result);
      $modx->documentObject[’template’]=$row[’id’];
      $modx->documentContent = $row[’content’];
      } else {
      $this->messageQuit("Error retrieving template.");
      }
      }
      }

      Create a TV called "TemplateSwitcher"
      Input Type: Radio Options
      Input Option Values: yes||no
      Default Value: no

      Assign this to your websites main template

      Now for any pages which you want to apply the template switcher to simply set the radio option on that page to Yes.



        http://www.onesmarthost.co.uk
        UK MODX Hosting with love.
        • 29181
        • 480 Posts
        This could be a handy feature to integrate, thanks for sharing!
          Adrian Lawley: www.adrianlawley.com
          • 33372
          • 1,611 Posts
          Just an FYI: There were a lot of problems associated with using the Template Switcher plugin in 0.9.5. They were critical in that it could disable your entire site, and it seemed to happen whether or not people were even using the plugin. I don’t know if this situation has been fixed in 0.9.6, but it’s definitely something to watch out for.
            "Things are not what they appear to be; nor are they otherwise." - Buddha

            "Well, gee, Buddha - that wasn't very helpful..." - ZAP

            Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
            • 37550 ☆ A M B ☆
            • 711 Posts
            Cheers ZAP, i will watch out for that and do some testing, hopefully with the changes i have made it shouldnt be too much of a problem as it should only run on a few pages and only if the webuser is logged in.

            Hope so anyway.

            Cheers
              http://www.onesmarthost.co.uk
              UK MODX Hosting with love.
              • 14930
              • 70 Posts
              Quote from: ZAP at Sep 23, 2007, 12:22 PM

              Just an FYI: There were a lot of problems associated with using the Template Switcher plugin in 0.9.5. They were critical in that it could disable your entire site, and it seemed to happen whether or not people were even using the plugin. I don’t know if this situation has been fixed in 0.9.6, but it’s definitely something to watch out for.

              Any news on this? Anybody use this plugin? I’m building a site with two distinct themes (summer & winter seasons), and all of the content doesn’t have to be duplicated, so I was looking for an easy way to have just the template changed..
                • 33372
                • 1,611 Posts
                I haven’t tried this plugin in a long time. I just create a snippet to add dynamic CSS to the document head wherever I need it, and this always works fine for me. It also allows you to cache most of the page and just add the CSS dynamically, so personally I’d go that route unless you have a very strong reason to switch the whole template.
                  "Things are not what they appear to be; nor are they otherwise." - Buddha

                  "Well, gee, Buddha - that wasn't very helpful..." - ZAP

                  Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                  • 14930
                  • 70 Posts
                  Thanks ZAP, I think I’ll look into that.
                    • 7810
                    • 26 Posts
                    Hi there. I tried out TemplateSwitcher and it works pretty well, however it interferes with MaxiGallery somehow so that galleries are not shown. I guess MaxiGallery doesn’t even start. It lists childagalleries OK, but shows nothing when inside a gallery. However tt works when TemplateSwithcher is disabled. Any ideas?
                    I’m using this plugin to switch between languages which is stored in TVs and the other template shows those TVs. Mimics the YAMS, becuase it was too buggy for me.

                    TemplateSwitcher 1.2, cookies are on;
                    MaxiGallery 0.5.2
                    MODx Evolution 1.0.2
                      MODx is great! Thanks for great work!

                      Portfolio, mostly MODx: dbdizainas.lt
                      • 22851
                      • 805 Posts
                      Hi Donatas.

                      I am currently going through the forum archives, trying to catch up and deal with YAMS related support request and bug reports etc. As a result I found your post above.

                      If you are able to find the time, I’d be very grateful if you could send me a message describing the problems that you encountered with YAMS so that I can attempt to fix them.

                      Thank you.
                        YAMS: Yet Another Multilingual Solution for MODx
                        YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
                        Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.