I've seen something similar done with the Mako templating library which allows mixing html and Python. We jokingly dubbed it PHPython, and it had grown into horrible spaghetti.
I think what happened was it started out as a quick and dirty thing that just grew and grew.