I have a piece of code that sniffs out if there is a cookie set or a variable passed in the url and if so puts it into a modx placeholder. It works great, I can then use modx->getPlacehouder to access that variable in the code, pass it to the stylesheet and access it from snippets....
<?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 there is a cookie set user_style to cookie user_style
}else{
$user_style = 0; // if not use default
}
};
$modx->setPlaceholder(user_style, $user_style);
?>
... however I’m having major trouble trying to get that code working in as a "snippet", I’ve tried various methods, setting a temp placehouder to avoid having the "_GET" query in the url.
Question, is it worth spending any more time on, as I am only doing it to keep things "tidy"?
Secondly, is there some syntax or a method to do this that escapes me?