How To Dynamic Web Rendering?

Adam Ruppe destructionator at gmail.com
Sat May 14 08:13:32 PDT 2011


Alexander wrote:
>  Sure, there are many pros. And one significant drawback - it
>  couldn't be easily embedded into HTML code.

Two notes: 1) actually, you can. 2) You don't want to.

1) I wrote a little program called dhp.d - write D in a PHP style.

http://arsdnet.net/dhp.d

About 100 lines of D - not exactly a fancy program - but it shows
a way you could do it.

Use dhp as an interpreter for your "script". You write

html here
<?d
  // D code here
?> // back to html


When dhp is run, it compiles the file on the fly. (This implementation
doesn't cache, but it could and should)

Then, it passes control to the newly compiled file, which runs and
outputs your stuff.


Literal html outside the <?d ?> tags is passed through just like php.
This is implemented by putting quotes around it and cgi.writting it
in the generated code.


2) While you could do it, you shouldn't do it. This is bad form even
in PHP. See part of my DOM template writeup for a brief on why:
http://arsdnet.net/web.d/dom.html

Basically, it gets ugly, fast.


More information about the Digitalmars-d-learn mailing list