Emiliano wrote:
> > I've been thinking about dynamic pages, more especially dynamic
> > styles. I'd like users to see the same content, but wrapped in different
> > styles according to their preferences. Clearly, Midgard uses a single
> > style association for each page, but I was wondering how we could choose
> > a different style, according to a user's preference.
> >
> > One thought was to make the style part of a wrapper function, i.e., in the
> > style ROOT element there would be PHP code to select which style the user
> > wants to see, then selectively output the appropriate elements. Has anyone
> > experimented with this approach?
>
> The problem with this is that the elements are pre-loaded. The code in
> the pages doesn't start to execute until these alements have allready
> been assembled to build the page. But in the "I don't know the
> solution, but I admire the problem" mindset, I'm open to suggestions
> on how to approach this.
I found this problem was simpler than I expected. I solved it with a style
that looks like this (I called it "FlexiStyle [TM] :-)" ):
FlexiStyle (style #24)
Style elements:
body1
body2
body3
head1
head1-script
head1-title
head2
head2-script
ROOT
ROOT1
ROOT2
ROOT3
ROOT4
Above is the top-level style. Note the four roots.
Now here is the content of the primary ROOT:
1: <?php
2: # This style is designed to allow selection of different styles,
3: # according to the user's preferences. Specifically, a cookie
4: # will be used to choose a style.
5: #
6: # First, we check to see if a cookie exists. If it does, then
7: # we use it to select from among the available styles.
8: # The cookie will contain a variable called mystyle, and the
9: # value will be a number between 1 and n where n is the max.
10: # number of styles. The default style is 1.
11: switch ($mystyle) {
12: case 1: ?>
13: <[ROOT1]>
14: <? break;
15: case 2: ?>
16: <[ROOT2]>
17: <? break;
18: case 3: ?>
19: <[ROOT3]>
20: <? break;
21: case 4: ?>
22: <[ROOT4]>
23: <? break;
24: default:
25: setcookie(mystyle,"1",time()+36000,"/"); ?>
26: <[ROOT1]>
27: <? break;
28: }?>
The code in the page that sets the cookie looks like this:
<?
# This page will take as a parameter the style number desired,
# and will set a cookie for the user known as "mystyle"
# with a value from 1 to 4. The value is passed as a parameter
# on the command line called "setmystyle".
switch ($setmystyle) {
case 1:
setcookie(mystyle,"1",time()+36000,"/");
break;
case 2:
setcookie(mystyle,"2",time()+36000,"/");
break;
case 3:
setcookie(mystyle,"3",time()+36000,"/");
break;
case 4:
setcookie(mystyle,"4",time()+36000,"/");
break;
default:
echo "Your style is currently set to $mystyle";
break;
}?>
<html>
<head>
<meta http-equiv="refresh" content="0; url=..">
</head>
<body>
This page is used to change style. If it does not automatically
continue after a change, please click <a href="..">here</a>.
<p>
Debug: $setmystyle=<? echo $setmystyle ?><br>
Debug: $mystyle=<? echo $mystyle ?></br>
</body>
</html>
It works just fine. A single click, and the complete style is different for
that user, and is remembered with a cookie. I'm so happy with Midgard, that I'm
planning to order myself 30 Midgard T-shirts! :-)
Cheers
Paul Gillingwater
http://www.lanifex.com
--
This is The Midgard Project's mailing list. For more information,
please visit the project's web site at http://www.midgard-project.org
To unsubscribe the list, send an empty email message to address
[EMAIL PROTECTED]