We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26439
    • 104 Posts
    Edit: third post is relevant, the first two are an excercise in "how not to....."

    This is a "How should I...." question, more than an hour of searching around the forum hasn’t got me any further.

    My goal is for a visitor to my website to be able to change the colours of the website.

    I am doing this so far by having a dynamic "css.php" page, as in..

    <?php
    header('content-type:text/css');
    
    $colour_scheme = $_GET['colour_scheme'];
    
    $backgrounds = array('#FFFFFF','#B4E39D','#F6F7DD');
    $background = $backgrounds[$colour_scheme];
    


    I then have this in the header of the template...

    <link rel="stylesheet" href="[(base_url)]assets/templates/template/{{Css_path}}" type="text/css" media="screen" /> 
    


    with the ((Css_path}} chunk containing...

    css.php?colour_scheme=0
    


    Now, what I would like is that the website visitor could use a form to change that $colour_scheme variable in the chunk, and eventually I would like the chunk to react to a cookie ( or some other method ) so that the whole site gets that colour scheme, for at least as long as the session.

    The reason for all this ( which may or not be a crazy way of going about things ) is I need the colours of the website to alter, I don’t want to have duplicate templates and have to alter them all, the same goes for the css file.

    ( I’m not trying to do a Zen Garden thing here, I’m thinking accessibilty ( colour blindness ) )

    So, am I trying re-invent the wheel here?

      • 26439
      • 104 Posts
      Ok, got as far as realising I need a snippet...

      <?php
      $css_var = isset($_REQUEST['css_var']) ? $_REQUEST['css_var'] : "1";
      return "$css_var";
      ?>
      


      ... all I need is to get that $css_var from the front page and I’ll be off........ EDIT: and I’ve got that far....

      <form method=post action="[~[*id*]~]">
      <input type=hidden name=css_var value="0" />
      <input type=submit />
      </form>
      


      .. just need to learn how to set a cookiie I guess.

      :)
        • 26439
        • 104 Posts
        Well for those of you sitting on the edge of your chairs wondering if I ever managed to work this one out, it turned out to be really really easy.

        All I needed to do was pass a url to the current page ( for some reason I thought that would be impossible using friendly url’s until I happenned on a MaxiGallery that was sending variables via the url ).

        After writing snippets and messing around with all the palava above, I found this syntax...

        <a href=[~[*id*]~]?user_style=0>00 grey</a><br />
        <a href=[~[*id*]~]?user_style=1>01 lime</a><br />
        


        I then use that variable to change the css file, I set a cookie, and every page reads that cookie...

        <?php
        if(isset($_GET[user_style])) // if user_style has been requested by the user in the url
        {
              $user_style = $_GET[user_style]; // define user_style
              setcookie("user_style",$_GET[user_style],time() + (86400 * 30), "/", "", 0); // set cookie for 30 days
        }else  // else if there is no user_style variable in the url
        {
           if(isset($_COOKIE['user_style'])) // see if there is a cookie
              {
              	$user_style = $_COOKIE['user_style']; // if so set user_style to cookie user_style
              }else{
              	$user_style = 0; // if not use default
              }
        };
        ?>
        


        I then throw the variable into the css.php file using...

        <link rel="stylesheet" href="[(base_url)]assets/templates/scraf01/colours_css.php?colour_scheme=<?php echo $user_style; ?>" type="text/css" media="screen" /> 
        


        ( I have since split the stylesheet, one concentrating on layout, one on colours )

        The stylesheet starts off with this.....you should get the idea
        <?php
        header('content-type:text/css');
        $colour_scheme = $_GET['colour_scheme'];
        
        switch($colour_scheme){
        	case '0':
            // gray scale
            $background = "#FFF";
        		$header_bg = "#FFF";
        ?>
        


        Well, that was so much fun I forgot to watch a rugby game, hope it comes in use for someone sometime.