Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Random templating

by sulfericacid (Deacon)
on Oct 08, 2004 at 05:21 UTC ( #397548=perlquestion: print w/replies, xml ) Need Help??

sulfericacid has asked for the wisdom of the Perl Monks concerning the following question:

This is a very interesting question for all you CGIers out there.

My new company web site has two different layouts. This was because I contracted two companies to make them independantly and I would choose the better of the two. But the thing is, I like them both.

Is it possible to create a CGI that'll load the moment index.html loads that will load one or the other template/web site? I want it so if they go to it and see one template that all the links will load in that very same template. But if they come back some X time later, they may see the other template or they may see the same one.

I don't simply want to redirect to template1.domain.com or such, I want it to load as domain.com/index.html regardless of which site it loads.

I might be missing an important concept, but I'm open to suggestions or feedback on this.



"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

Replies are listed 'Best First'.
Re: Random templating
by ikegami (Patriarch) on Oct 08, 2004 at 05:27 UTC
    Of course! Keep track of the user's prefered template in a session/cookie, and feed the appropriate filename to your template engine based on this value. It's even simpler if your templates are only different in terms of CSS like at CSS Zen Garder, where you can simply return a different .css based on the session/cookie.
Re: Random templating
by BigLug (Chaplain) on Oct 08, 2004 at 05:40 UTC
    Sulfuric:

    This is a bad idea™. You will disorient your visitors to the point where they won't be sure where they are. Consisancy is the most important thing in branding. Imagine if every MacDonalds had a random color/font for their 'M' .. you'd not be sure if it was McDonalds or not.

    The only exeption I make to that rule is for websites-as-art which, as you've had other people create the look, is not what your site is. Art sites can change as often as they please because the site itself is a piece of art.

    All that being said, here's the answer you're looking for:

    If your site is CGI based then it's as simple as storing a cookie for however long you want them to get the same template. Read the cookie on each page load and return templates based on the cookie.

    If your site is file based, then you want to store your two sites in directories like www.yoursite.com/site1/page.htm and www.yoursite.com/site2/page.htm. Then in apache (which I'll assume you're using) you need to do a mod_rewrite. It's not a two second job and its really not a perl question so I'll leave it at that. Take a look at the apache documentation for mod_rewrite for more information. You'll basically be rewriting www.yoursite.com/page.htm with one of the above links based on a cookie. (Remembering to have some fall back for non-cookie people ... like mod the day of the week).

    Just remember that if your site is file based, you'll have to update files in both directories every time you make a change.

    Once again though, let me reiterate that this is a bad idea™ and that your users will become confused. I once saw a site with multiple designs but I had to choose to change from the default so at least I knew I was at the same site I'd been at last time.


    Cheers!
    Rick
    If this is a root node: Before responding, please ensure your clue bit is set.
    If this is a reply: This is a discussion group, not a helpdesk ... If the discussion happens to answer a question you've asked, that's incidental.
Re: Random templating
by saskaqueer (Friar) on Oct 08, 2004 at 05:31 UTC
    <rant>
    I realize I am not helping you with the actual question you have posted, but I feel it is necessary to point out that multiple templates for one website is one of the most horrid things you can do to a user. I login to perlmonks expecting everything to look the way it did the last time I visited. You may think both templates are worthwhile, but having your pages look different on each separate visit to the site is a Bad Thing™. You will manage to do nothing more than confuse, frustrate, and irritate your users. Today's lesson: one website, one template.
    </rant>
      Don't be too quick to judge multiple templates as 'A bad thing'. Templates that respond to the user agent (IE, Mozilla, ...) or the method of access WAP, text only etc. are common place. After all, one of the main drivers for using templates is the separation of content from presentation.

      As with anything, this seperation can be abused. I concede that poor use of templating is going to hack the users off. I guess that this is just an example of poor design.

        Sorry, perhaps I should have specifically stated that multiple visual templates are horrible. Obviously, permitting different templates for uses such as WAP, text-only, etc. are a good thing. My concern is website designers who take it upon themselves to alternate their pages' templates for visual browsers (IE, Netscape, Opera, etc.).

      You cannot say it would be a bad thing in every situation. The people I am marketing to aren't new to the internet and they're not too young or terrible aged in a sense that they won't understand.

      Having two sites would be creatively different. Not just two pages that look similar, but two complete opposite sites. Then maybe give them the opportunity to store a permanent cookie so they'll always see the one they prefer.



      "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

      sulfericacid
        If the Monastery were to randomly change templates on me, I'd stop using it. Your users will do the same, unless they are design schoool wankers. Sure, it might not be a bad thing in *every* situation, but it's sufficiently silly that I'll still assume it's a bad idea in any particular situation until you can prove otherwise.

        Your users' experience level is irrelevant. Your users' age is irrelevant. It wouldn't be creatively different, it would be stupid.

Re: Random templating
by dws (Chancellor) on Oct 08, 2004 at 06:21 UTC

    Is it possible to create a CGI that'll load the moment index.html loads that will load one or the other template/web site?

    If you're using Apache, you could use mod_rewrite to rewrite the URL to invoke a CGI, passing it index.html; then select templates at random.

Re: Random templating
by tmoertel (Chaplain) on Oct 08, 2004 at 15:49 UTC
    Dear sulfericacid,

    Many people are warning you that randomly switching the layout and look-and-feel of your site is likely to harm your site's usability. However, only you are in a position to make that call. Maybe you know something that we don't. Maybe your site is all about art and exploration, or maybe your users come to your site for an "experience" and not to find information, do their jobs, or purchase a product. In any case, it's your call to make.

    What's particularly interesting about your situation is that it provides a perfect opportunity for all of us to learn something. Is the common wisdom – that swapping UIs frequently is "bad" – applicable to your site?

    Let's find out!

    Let's design a simple experiment to measure the effect of random UI swapping on your users:

    1. Partition your users into two equally sized groups: the experimental group (those who will be subjected to random UI swapping every time they log in) and the control group (those who won't). To eliminate bias among the UIs, each user in the control group should be randomly assigned one of the two new UIs, which then becomes that user's UI for the duration of the study.
    2. Whenever users log in, determine which group they are in and select their UIs accordingly.
    3. After a month or so, analyze your logs, site feedback, etc. to determine if there is a significant difference in behavior between the experimental and control groups. (For example, if common wisdom is correct, we would expect that site usage among experimental-group users to drop off w.r.t. control-group users.)

    Sounds like fun, don't you think? When it comes to your site, care to prove the experts wrong? (Or right?)

    Cheers,
    Tom

    Update: clarified wording.

      I agree the proof is in the pudding and benchmarking is crucial to having valid opinions but I've seen the pudding served to 10-20 million users a day all year and even minor changes like moving a linked heading lower or higher relative to other page blocks does change usage. This isn't really an experimental problem any more. What if someone moved your mousepad every morning? Oh, that's amusing.

      As discussed, a pure design site or something might make constant change interesting or desirable, otherwise it's probably a vanity choice and not really in your users' good interests. And even the design sites that do this kind of thing stay strongly branded with a big headline/logo/etc. I can't think of a single site I've visited more than once in 10 years that does this though. On the other hand, letting users select a template or stylesheet is most definitely in their interest and good service. And if it's your site, it's your call.

      The other problem with doing it via two different code bases instead of CSS or templates is you just locked yourself into a future course if you intend to keep users who do like the different systems happy. If you upgrade, redraft, change then your costs/time just doubled. If you can change one of the systems to run with the template of the other (the end product of HTML doesn't care what created it) you'll probably be happier as time goes by. Plus you're in an unusual and enviable position. You have two code bases done and running, and you could pick the better written of them.

Re: Random templating
by dragonchild (Archbishop) on Oct 08, 2004 at 12:06 UTC
    It sounds as if you don't want any static content at all. Use mod_redirect to redirect any URL with a /$ in it to /cgi-bin/main.cgi (or whatever) and you're good.

    For the record, I don't think you should require your users to have a randomly-selected template. Providing different skins is a good thing, but the user should be in control of how s/he views your site. It's your information, but it's their eyes. Additionally, what if the user is color-blind? One time, they see a green and blue site (which is fine), then the next time they see a green and red site (which isn't fine). Uh-oh ...

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Re: Random templating
by schumi (Hermit) on Oct 09, 2004 at 18:56 UTC
    Hello sulfericacid

    You have so far read a lot about why using several different templates can be a bad or a good idea. I suppose you known what you're doing there, or give it a good thought now after having read all the above posts.

    Having said that, off the top of my hat I'd recommend HTML::Template for the task. It takes a bit of fiddling to get your mind around how it does the more compliacted things like loops and such, but once you know the drill it's a blast. Entering this into Super Search should give you plenty of information as well. There's even a review of the module by defyance.

    You can still use Cookies to keep track of the users' preferred template, or whatever mechanism takes your fancy.

    Hope this helps!

    --cs

    There are nights when the wolves are silent and only the moon howls. - George Carlin

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://397548]
Approved by FoxtrotUniform
Front-paged by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2022-05-22 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (81 votes). Check out past polls.

    Notices?