We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26435
    • 1,193 Posts
    Does anyone know how I can implement this into my MODx installation? This is the PHP Template switcher that http://www.csszengarden.com uses.

    <?php
    
    $tempCSS = $HTTP_GET_VARS["cssfile"];
    if ($tempCSS != "") {
    	$loadCSS = $tempCSS;
    } else {
    	/* sets a default CSS file if no querystring specified */
    	$loadCSS = "default.css";
    };
    $currentDesign = $loadCSS;
    
    ?>
    
    	<!-- make sure this goes somewhere between <head> and </head> -->
    	<link rel="stylesheet" type="text/css" href="<?php echo $loadCSS; ?>" title="default" media="screen" />
    
    	<!-- to link any particular stylesheet later, just add a querystring to the current page: -->
    	<a href="thispage.html?cssfile=/002/002.css">Change Style</a>
    
    
    

    I tried copy/paste as is into the <head> of my html without success.

    -sD-
      Husband, Father, Brother, Son, Programmer, Atheist, Nurse, Friend, Lover, Fighter.
      All of the above... in no specific order.


      I send pointless little messages
      • 18397
      • 3,250 Posts
      This would have to be coded into a snippet as templates cannot have php code in them. Not hard at all...
        • 26435
        • 1,193 Posts
        So could I copy the code into a snippet, let say called [[Switch]], then call [[Switch]] in my template? Would it be parsed properly that way?
          Husband, Father, Brother, Son, Programmer, Atheist, Nurse, Friend, Lover, Fighter.
          All of the above... in no specific order.


          I send pointless little messages
          • 32241
          • 1,495 Posts
          Paste this code into your snippet and name it "CSSTemplateSwitcher"

          $tempCSS = $HTTP_GET_VARS["cssfile"];
          if ($tempCSS != "") {
          	$loadCSS = $tempCSS;
          } else {
          	/* sets a default CSS file if no querystring specified */
          	$loadCSS = "default.css";
          };
          return $loadCSS;
          



          After that, right in your template, call this snippet in your external stylesheet calling.

          <link rel="stylesheet" type="text/css" href="http://domain.com/assets/templates/CSS_TEMPLATE_FOLDER/[!CSSTemplateSwitcher!]" />
          



          That’s all

          Hopefully it works as what you expect that to be.


          Regards,
          Wendy Novianto
            Wendy Novianto
            [font=Verdana]PT DJAMOER Technology Media
            [font=Verdana]Xituz Media