Totalement crétin

Pub acer

IE CSS background flicker : bunch of solutions

Making a CSS image based navigation with rollover I got the infamous CSS background flickering bug of Internet Explorer 6. I have lost several hours trying to solve the problem by different ways.

This is the first workaround that works fine for me :

I hope that will help someone to find a solution faster than me.


A template translator in 20 lines of code

Looking at the architecture of a big CMS I am thinking that my templating software is overcomplicated.

With templight, I have produced a kind of syntax checker and an interpreter for a high level templating language. It's maybe a solution with a compiled language like .NET, Java or C++. But certainly not with a dynamic language like PHP or Python.

Dynamic languages have a big advantage over the others : you can easily produce programs that produce other programs and start to use them immediatly.

If you can understand this fact, you can also understand that it is 10 times more easy to write a templating language interpreter in a dynamic language.

The idea is simple :

  1. Choice a dynamic language for the work
  2. Choice a templating language
  3. Write a program that translate the templating language in the dynamic language

I was able to produce a little translator in minutes that can do most of the basic things needed for a templating language. And it was only 20 lines of PHP. I realize now that my previous work was not required (but it was fun). It's not necessary to re-invent the wheel by producing a compilator and an interpreter. Just use the one provided by the dynamic language.

My templating language file :

        <title>{{block title}}</title>
        <p>In PHP I am sure of that :
            {{if 1==2}}
            {{elseif 10>0}}
            nothing interessting
            {{loop testArray}}

My translate program (delete the space in $ 1 variables):

function translate_template($c)
     // escape the simple quote
     $c = preg_replace('#([^\])\'#si','\'',$c);
     // conditionals
     $c = preg_replace('#{{if (.*?)}}#si','\'; if($ 1){ echo \'',$c);
     $c = preg_replace('#{{elseif (.*?)}}#si','\'; }elseif($ 1){ echo \'',$c);
     $c = preg_replace('#{{else}}#si','\'; }else{ echo \'',$c);
     $c = preg_replace('#{{endif}}#si','\'; } echo \'',$c);
     // loops
     $c = preg_replace('#{{loop ([\w]*)}}#si','\'; foreach($ as $item){ echo \'',$c);
     $c = preg_replace('#{{endloop}}#si','\'; } echo \'',$c);
     $c = preg_replace('#{([\w]*)}#si','\'; echo $item[\'$ 1\']; echo \'',$c);
     // blocks
     $c = preg_replace('#{{block ([\w]*)}}#si','\'; echo $; echo \'',$c);
     return '<?php echo \''.$c.'\'; ?>';
$c = translate_template((file_get_contents('tpl.html')));
$fp = fopen('cache/tpl.html','w');

$title = 'My nice Page';
$testArray = array(array('text'=>'hello'),array('text'=>'world'));

The output produced by translate_template function :

<?php echo '<html>
        <title>'; echo $title; echo '</title>
        <p>In PHP I am sure of that :
        '; if(1==2){ echo '
        '; }elseif(10>0){ echo '
        '; }else{ echo '
        nothing interesting
        '; } echo '
        '; foreach($testArray as $item){ echo '
        <li>'; echo $item['text']; echo '</li>
        '; } echo '
</html>'; ?>

The final result :