3 ms·
What if you want to repeat a similar chunk of HTML in a loop? What if you want variables? Functions? <Insert general purpose programming language construct here
by sreque 18y ago
What if you want to repeat a similar chunk of HTML in a loop? What if you want variables? Functions? <Insert general purpose programming language construct here>? The world has spent too much time trying to hammer programming language constructs into XML-based languages and templating systems. There simply has to be a better, way, but no one has successfully come up with one that satisfies everybody yet.
- jonknee 18y agoThat's where template systems like Django's and stuff like PHP come in handy. I can pass either off to a designer who knows HTML and they are off to the races.
- dasil003 18y agoCertainly there could be a better way, but HTML and CSS are what we have (and frankly they work pretty well considering that the web comprises mostly documents). Emitting HTML from a programming language can be useful, but it doesn't solve the fundamental inelegance of nested markup. Solutions like this are just indirecting the problem, adding another layer of complexity without a meaningful abstraction.
- abstractbill 18y ago...considering that the web comprises mostly documents... I found this interesting. I've been doing web stuff since 1996, and I would have agreed with you back then. But these days my perception is that the majority of stuff on the web should be considered to be applications rather than documents.
- dasil003 18y agoFair enough, though I would consider many many web apps to be document-oriented. It's a slippery definition to be sure.
- cosmo7 18y agoMy project, phpSprockets (http://code.google.com/p/phpsprockets/ http://code.google.com/p/phpsprockets/) does nested markup by working as a node system. After all, if you're going to generate HTML in code you might as well do it in an object oriented way. $table = new Sprocket( 'table' ); $tr = $table->tr(); $tr->td( "OMG I'm in a sprocket" ); I've done similar things using XElement in C#, though using PHP's magic methods makes for very short readable code. I agree that templates are handy for separation of concerns though.