Archive for January, 2006

Return different stylesheets based on screen resolution

Saturday, January 28th, 2006

A friend of mine wanted to use 2 different stylesheets, based on the screen resolution of the browsing computer. He found this script to differentiate between users with screens < 800 width, and users having bigger.

Unfortunately, with cookies disabled, you will find yourself browsing an endless looping white page. So I showed him how to do this the right way; and I thougth I might share it with anyone searching for something similar

<link rel="stylesheet" type="text/css" media="all" href="style_800x600.css" id="style_low" />
<link rel="alternate" type="text/css" media="all" href="style_1024x768.css" id="style_high" />
<script type="text/javascript">
function checkStyle(){
    if (screen.width > 800){
       document.getElementById('style_low').rel = 'alternate';
       document.getElementById('style_high').rel = 'stylesheet';
    }
}
window.onload = checkStyle;
</script></link>

simpleTemplate - a simple templateparser in PHP

Friday, January 6th, 2006

In a project of mine I wanted to use a templateparser to easily output some HTML. I started with Smarty; but found it too heavy weighted; with it’s endless list of classes and files I didn’t want. So I continued with TinyButStrong which proclaims to be simple with only one class. Having tried some time I didn’t like it either. It’s code is unreadable to me; and so are the templates. Even worse; it uses blocks instead of arrays; so I needed to define all my arrays as blocks before the templateclass could use it. So I started thinking about creating something myself. As Google can tell you, other people have thought the same thing. I hope you can spot what makes mine better by looking at the code, or just start using it. Anyways, like so many people I think my code might be useful for others.

simpleTemplate supports if-statements, variable getting and setting, foreach-loops, blocks and a simple yet effective caching mechanism. I do have a list of features I am going to add so keep an eye on sjon.blog for any updates to the code. Here it is:

Comments welcome!

MVC - nothing new there is it?

Thursday, January 5th, 2006

Reading MVC and web apps: oil and water after discussing about MVC today I think the article is pretty much right about MVC. At the office today we pretty much concluded that MVC was nothing more than a strict separation of your database, templateparser and actual engine just ‘doing’ the rest. This strict separation prevents spaghetti-code and unstructured calls between the various aspects of these elements of MVC. However, this separation should be common among web developers and there should be no need to call it MVC. It’s the same as “Don’t use registered_globals in your application”. This undefined fuzz about separation I like the comparison between where we are now, and where we were two years ago, it makes you wonder what the web will be like in 2007 :)

PS, haven’t read about CRUD yet? You should!

New monitor

Tuesday, January 3rd, 2006

I have just installed my new monitor; the BenQ FP202W. I must say, it is a real beauty. It is much more easy on the eyes then a CRT monitor. Since I couldn’t find any examples of a xorg.conf file I thought I’d post how I got mine working. It is too easy actually , but with ‘ddc’ as a module you don’t need to add or change anything except for the identifier maybe:

Section "Monitor"
Identifier "BenQ FP202W"
EndSection

Now all I need to do is find some nice wallpapers sized 1680×1050 :D

BenQ FP202W