We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33992 ☆ A M B ☆
    • 455 Posts
    Hi,
    in MODxHost template and template page, there is a part for changing CSS of page.
    is it possible that the css switched by user put in other pages for him/her while visiting site?
    it means, user select the css which it likes and visit all pages with selected style not default css.

    Regards
    AHHP
      God loves me. 【ツ】


      MODX.ir (Persian Support)

      Boplo.ir/modx/ (Persian)
      • 15152
      • 360 Posts
      Let me clarify what you’re asking, because I think I’m looking for the same thing.

      I want the user to come to my site and to be able to choose a link to select one of 4 different looks for the site. The change would be site-wide. I can easily set-up 4 different templates (just duplicate and rename the template) and switch the style sheet for each template.

      Once the user selects a template that’s how they will view the site. I believe the ’Template Switcher’ plug-in allows this. I don’t know how to code it for the front-end. Can someone help with that?

      What code exactly?
      Can it be set up as a link?

      Thanks for the help!
        There are no boring projects. Only boring executions. ~ Etzkorn
        www.impress-design.com
        • 33372
        • 1,611 Posts
        The Template Switcher plugin was a great idea and worked well in 0.9.2.x, but unfortunately it completely freaks out in 0.9.5+ and can cause your site to crash completely. It was originally included in the standard 0.9.5 release but has since been removed. So you don’t want to use the Template Switcher plugin to do this.

        I think that I would just create a simple plugin that checks for a cookie that will determine the CSS to use. It would run on the OnWebPageInit system event (so it can set a cookie before any output has been sent) and set a placeholder that you could use in a single template to select which CSS file to load. Something like this:

        $userTemplate='your-default-style';
        
        if (isset($_GET['style'])) {
           $userTemplate=$_GET['style'];
           setcookie("style",$userTemplate,time()+604800, "/", "", 0);
        }
        elseif (isset($_COOKIE['style'])) {
           $userTemplate=$_COOKIE['style'];
        }
        
        $modx->setPlaceholder('userTemplate',$userTemplate);


        Then you would just add something like
        <link rel="stylesheet" type="text/css" href="[+userTemplate+].css?" />
        to the head of your template.

        You should probably also check that the value you get from either the GET string or COOKIE is in fact a valid CSS file in the plugin by comparing it against an array of valid styles or something, but this basic approach should work (and it doesn’t switch the template itself, which seems to be the root of the Template Switcher plugin problem).
          "Things are not what they appear to be; nor are they otherwise." - Buddha

          "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

          Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
          • 15152
          • 360 Posts
          Okay. I got this figured out. ’Template Switcher’ is standard in the 0.9.5 install. Follow the recommended set-up from the download page, including - and this is important - turn off page caching.

          Duplicate your current template (or create a new one) and link it to the proper style sheet.

          Put links in your template to change the style / look and feel (mine are in the left-hand column link section) The link will look like this: <a href="index.html?template=Front End Summer">. The imporant part is the ?template=name of template. (My template name is Front End Summer in the example). Once clicked, all of the pages will be of the new template.

          You can see this in action at www.jackmcdaniel.net

          I’m messing around with something else. If you want a real different look go to www.jackmcdaniel.net and type in after the url "?template=Front End Sinister"

          I haven’t had any problems with it yet, but then, I do have caching off. This could slow down really busy sites.

          Hope this helps
            There are no boring projects. Only boring executions. ~ Etzkorn
            www.impress-design.com
            • 33372
            • 1,611 Posts
            As far as I know, you should not use the Template Switcher plugin at all anymore. There have been too many serious problems associated with it on 0.9.5+ installations, and it is now deprecated. In fact I think it should be removed from both the release and the Repository unless there’s been some progress in debugging it that I’m not aware of.
              "Things are not what they appear to be; nor are they otherwise." - Buddha

              "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

              Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
              • 8619
              • 229 Posts
              Try this:

              http://alistapart.com/stories/alternate/

              Not sure how to integrate into MODx, but you could probably easily make it work.